File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ package os
5
5
// license that can be found in the LICENSE file.
6
6
7
7
import (
8
+ "os"
9
+ "strings"
10
+
8
11
"github.com/go-python/gpython/py"
9
12
)
10
13
@@ -13,7 +16,8 @@ func init() {
13
16
methods := []* py.Method {}
14
17
15
18
globals := py.StringDict {
16
- "error" : py .OSError ,
19
+ "error" : py .OSError ,
20
+ "environ" : getEnvVariables (),
17
21
}
18
22
19
23
py .RegisterModule (& py.ModuleImpl {
@@ -25,3 +29,15 @@ func init() {
25
29
Globals : globals ,
26
30
})
27
31
}
32
+
33
+ // gets and parses all process enviroment variables
34
+ func getEnvVariables () py.StringDict {
35
+ env_variables := os .Environ () // this gets all the enviroment variables
36
+ dict := py .NewStringDict ()
37
+ for _ , evar := range env_variables {
38
+ key_value := strings .Split (evar , "=" ) // returns a []string containing [key,value]
39
+ dict .M__setitem__ (py .String (key_value [0 ]), py .String (key_value [1 ]))
40
+ }
41
+
42
+ return dict
43
+ }
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ print (os .error )
4
+ print (os .environ .get ("HOME" )) # prints $HOME variable
You can’t perform that action at this time.
0 commit comments