Chris Nehren on 24 Dec 2010 06:23:19 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Get Python Environmental Varibles


On Dec 24, 2010, at 8:55 AM, Casey Bralla wrote:

> On Friday 24 December 2010 7:52:42 am Casey Bralla wrote:
>> I'm working on a cgi-bin script in Python, and I'd like to be able to read
>> environmental variables.  There is a nifty routine for this in python call
>> os.getenv.  The only problem is that you have to know what the
>> environmental name is, before you can get it's value.
>> 
>> I'd like to read the entire list of variables, and then use that to decide
>> which one will have the utility I need (I'm looking for some path info, but
>> also want to understand the whole system.)
>> 
>> Does anybody know how to get a complete list of environmental variables
>> from a running python program?
> 
> 
> I used the subprocess.Popen routines to run the "env" command which gave me 
> the list of variables.

That's silly and an ugly kluge.

>>> os.environ.keys()
['PERL_MM_OPT', 'SSH_CLIENT', 'LOGNAME', 'USER', 'HOME', 'PATH', 'SSH_AGENT_PID', 'LANG', 'TERM', 'SHELL', 'MANWIDTH', 'BLOCKSIZE', 'FTP_PASSIVE_MODE', 'SLASHEMOPTIONS', 'EDITOR', 'NETHACKOPTIONS', 'SSH_AUTH_SOCK', 'NNTPSERVER', 'VISUAL', 'LC_ALL', '_', 'BROWSER', 'PERL5LIB', 'SSH_TTY', 'PERL_AUTOINSTALL_PREFER_CPAN', 'HISTCONTROL', 'SHLVL', 'PWD', 'PERL_MB_OPT', 'MAIL', 'SSH_CONNECTION', 'PAGER']
>>>

Methinks you should consult a python tutorial before you make a bigger mess.
-- 
Thanks and best regards,
Chris Nehren

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug