문제

How can I lookup environment variables (e.g. export HG_USER from .profile) using python code in Mac OS X?

도움이 되었습니까?

해결책

os.environ is a dictionary containing all the environment variables. You need to import os before you can use it. So, for example HG_USER would be accessed by os.environ['HG_USER'].

다른 팁

Use the os module:

import os
os.environ

Returns a dictionary with the environment variables as keys.

Use os:

>>> import os
>>> print os.environ["PATH"]

You can also the helper function os.getenv(varname[, value]) which will return the value of environment variable varname, and if it not present will return value which defaults to None

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top