Python Nautilus script

Michel Leunen michel at nospam.please
Mon Sep 15 15:46:47 EDT 2008


Diez B. Roggisch a écrit :

> There shouldn't be a difference between a shell-script and a 
> python-script. Environment-variables are a unix-process-thing, and thus 
> the rules that govern them apply to *all* processes - the shell is one 
> of these, there is nothing special to it.
> 
> If the shell-script gets the variable, the python-script will as well.

Yes, that's what I thought too but try this: open a terminal and type

$ echo $HOSTNAME

you will get the name of your computer.
Now try this instead:

$ python
 >>> import os
 >>> 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'
 >>>

It appears that's because HOSTNAME is not exported.
But in the case of Nautilus script, how to workaround this issue?

-- 
Michel Leunen
http://linux.leunen.com



More information about the Python-list mailing list