environment variable issue
Fredrik Lundh
fredrik at pythonware.com
Mon Sep 15 14:52:41 EDT 2008
Michel Leunen wrote:
> Could someone explain me what I'm doing wrong here? I'm trying to
> retrieve the value of an environment variable in Ubuntu 8.04 like this:
>
> >>> import os
> >>> os.environ['USER']
> 'michel'
>
> This works but this doesn't:
>
> >>> os.environ['HOSTNAME']
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
> raise KeyError(key)
> KeyError: 'HOSTNAME'
>
> Why is it working in the first case but not in the second one. I must be
> missing something but it seems I'm not able to figure it out.
this might help:
http://mail.python.org/pipermail/python-list/2008-September/507933.html
(scanning the subjects of recent and ongoing threads before posting is
always a good idea).
</F>
More information about the Python-list
mailing list