Environment Variables in Python on Linux

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

    Another possibility is to use pdb, or some other python debugger instead, and change os.environ at the python level, rather than the C level. Here's a small recipe I posted to interrupt a running python process and provide access to a python console on receiving a signal. Alternatively, just stick a pdb.set_trace() at some point in your code you want to interrupt. In either case, just run the statement "import os; os.environ['SOME_VARIABLE']='my_value'" and you should be updated as far as python is concerned.

    I'm not sure if this will also update the C environment with setenv, so if you have C modules using getenv directly you may have to do some more work to keep this in sync.

提交回复
热议问题