Python Get System Environment Variable Linux
I've exposed one system environment variable say KEY1 with value VALUE1 in /etc/profile (I know, I know, it's probably bad) Now in my shell if I do $ echo $KEY1 VALUE1 But when I
Solution 1:
You might not have exported the variable. You can think of export as a way of making a shell variable public and not private to the shell. Take a look at the export man page.
➜ ~ K=1
➜ ~ echo $K
1
➜ ~ python -c "import os; print os.environ.get('K')"
None
➜ ~ export K=1
➜ ~ python -c "import os; print os.environ.get('K')"
1
Post a Comment for "Python Get System Environment Variable Linux"