How to set or get enviroment variable

Dave Angel davea at davea.name
Sat Mar 30 17:07:41 EDT 2013


On 03/30/2013 04:39 PM, Nac Temha wrote:
> Hi, I want to get and set enviroment variable of linux system. Actually I
> can do this issue using os module but How can I do without using os module?
> Is there another way?
>
>

As Chris has said, the os module is the way to get and modify the 
environment of your Python program, whether on Linux or elsewhere.

However, the wording of your question was ambiguous enough that I 
thought I'd better clarify.  Changing the environment within one 
application does not in general affect any other.  So if you had 
thoughts of setting an environment variable from your python script, and 
exiting, and having the next thing you ran from the shell affected, 
better think again.

That sort of thing needs to be done from the shell, rather than from a 
script.  And while there are tricks to do, they're Linux-- (or Windows, 
or whatever) tricks, not Python ones.


-- 
DaveA



More information about the Python-list mailing list