-3

I add a variable called env to /etc/profile, but I didn't export it, now I want to get the value of env in python, but I get nothing, my code is as below:

>>> import os
>>> env = os.environ.get('env')
>>> print env
None
akshat
  • 1,219
  • 1
  • 8
  • 24
  • 2
    Please don't post code in picture, add it to the post instead. – cyberbemon May 16 '18 at 07:57
  • 1
    Possible duplicate of [Python Get System Environment Variable Linux](https://stackoverflow.com/questions/44919298/python-get-system-environment-variable-linux) – cyberbemon May 16 '18 at 07:59
  • just try os.environ to get a list of environmental variables and check if `env` exist –  May 16 '18 at 08:00
  • Did the changes apply to you console session? Check with `env` on the console! – Klaus D. May 16 '18 at 08:03

1 Answers1

0

thanks for everybody, i've solved this problem, the reason is that I didn't use the upper case of 'env', although I wrote lowercase in the profile file, I must get it in capitals.

# my code like this:
import os
environ = os.environ  
env = environ.get('ENV')
# profile like this:
env=production