Environment Variables in Python on Linux

前端 未结 5 1147
别那么骄傲
别那么骄傲 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:12

    That's a very good question.

    It turns out that the os module initializes os.environ to the value of posix.environ, which is set on interpreter start up. In other words, the standard library does not appear to provide access to the getenv function.

    That is a case where it would probably be safe to use ctypes on unix. Since you would be calling an ultra-standard libc function.

提交回复
热议问题