Changing environment variables into python variables
thomas at xs4all.nl
Fri Jun 4 01:47:44 EDT 1999
On Fri, Jun 04, 1999 at 07:27:28AM +0200, Thomas Wouters wrote:
> > What am I doing wrong here? How can I, at runtime, define a variable
> > and assign it a value?
> You need to use exec(), not eval(). This is probably a FAQ, but i'm not sure
> if it's in the FAQ. From the Python Documentation however:
Oh, i forgot to warn you: You probably want to be very sure you dont have an
environment variable containing, for instance:
'You\'re a loony.", posix.system("rm -rf /"), "'
Dont forget -- you already imported posix or os so you can get to the
environment variables, which means you give them access to the 'remove' and
'system' functions, as well.
$ echo $test
You're a loony.", posix._exit(1), "
Python 1.5.1 (#1, Sep 3 1998, 22:51:17) [GCC 18.104.22.168] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import posix
>>> for var in posix.environ.keys():
... command = var + '="' + posix.environ[var] + '"'
... print command
test="You're a loony.", posix._exit(1), ""
$ echo $?
being-paranoid-doesn't-mean-the-bastards-aren't-out-to-get-you-ly y'rs, Thomas
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list