We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f3dd9ab commit e8813f3Copy full SHA for e8813f3
os/example_getenv.py
@@ -0,0 +1,3 @@
1
+import os
2
+
3
+print(os.getenv("HOME", "def"))
os/os/__init__.py
@@ -32,6 +32,7 @@
32
getpid_ = libc.func("i", "getpid", "")
33
waitpid_ = libc.func("i", "waitpid", "ipi")
34
system_ = libc.func("i", "system", "s")
35
+getenv_ = libc.func("s", "getenv", "P")
36
37
R_OK = const(4)
38
W_OK = const(2)
@@ -204,6 +205,12 @@ def system(command):
204
205
check_error(r)
206
return r
207
208
+def getenv(var, default=None):
209
+ var = getenv_(var)
210
+ if var is None:
211
+ return default
212
+ return var
213
214
def fsencode(s):
215
if type(s) is bytes:
216
return s
0 commit comments