os.putenv ?

Jacek Generowicz Jacek.Generowicz at cern.ch
Fri Mar 28 09:10:36 EST 2003


Stuart Bishop <zen at shangri-la.dropbear.id.au> writes:

> On Friday, March 28, 2003, at 06:54  PM, Jacek Generowicz wrote:
>
> > Great. Now ... what if the user uses tcsh ..
> 
> % exec env GRR="This is a late parrot." $SHELL
> % echo $GRR
> This is a late parrot.

That looks intereting.

> Or you can use the script-generated shell commands approach, although
> this is overkill unless you are trying to do something more complicated
> (such as insert elements into PATH or CLASSPATH etc).

This is exactly the sort of thing I want to do.

> #!python
> import os
> m = { 'GRR': 'This is a late parrot.' }
> if os.environ['SHELL'].endswith('csh'):
>      for k,v in m.items():
>          print "setenv %s '%s'" % (k,v)
> else:
>      for k,v in m.items():
>          print "export %s='%s'" % (k,v)
> 
> 
> % eval `python_env`
> % echo $GRR
> This is a late parrot.

Also interesting.

Thanks.




More information about the Python-list mailing list