Environment Variables in Python on Linux

前端 未结 5 1138
别那么骄傲
别那么骄傲 2020-12-05 11:53

Python\'s access to environment variables does not accurately reflect the operating system\'s view of the processes environment.

os.getenv and os.environ do not func

5条回答
  •  醉酒成梦
    2020-12-05 12:14

    You can use ctypes to do this pretty simply:

    >>> from ctypes import CDLL, c_char_p
    >>> getenv = CDLL("libc.so.6").getenv
    >>> getenv.restype = c_char_p
    >>> getenv("HOME")
    '/home/glyph'
    

提交回复
热议问题