Environment variables not visible from Python

Kushal Kumaran kushal.kumaran+python at gmail.com
Thu Sep 22 02:40:08 EDT 2011


On Thu, Sep 22, 2011 at 11:42 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> I don't understand why some environment variables are not visible from
> Python.
>
> [steve at wow-wow ~]$ echo $LINES $COLUMNS $TERM
> 30 140 xterm
> [steve at wow-wow ~]$ python2.6
> Python 2.6.6 (r266:84292, Dec 21 2010, 18:12:50)
> [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import os
>>>> (os.getenv('LINES'), os.getenv('COLUMNS'), os.getenv('TERM'))
> (None, None, 'xterm')
>
>

I have this:

$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getenv('LINES')
>>>
$ python -S
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
>>> import os
>>> os.getenv('LINES')
'35'
>>>

I hope it helps narrow things down somewhat.

-- 
regards,
kushal



More information about the Python-list mailing list