Python for a PHP user, how do i...?
richw at objenv.com
Tue May 15 17:24:33 EDT 2001
In article <9ds48t$1rt$1 at tyfon.itea.ntnu.no>, "Magnus Lie Hetland"
<mlh at idi.ntnu.no> wrote:
>> >>> spam="print 'eggs'"
>> >>> eval(compile(spam,'<string>','exec'))
> Why the compile? Why not just eval(spam)?
Now I'm not claiming there isn't a better way, just that the above method
will work for any correct python not just single method invocations as
eval seems to. I'm way out of my depth here as I have only had to stoop
to such nonesense on one occasion and am therefore pretty unfamilar with
the inner workings of eval and friends.
Stop the presses. I just found 'exec'. That's the general purpose
function I was looking for. Don't do the compile nonesense I previously
recommended. exec does it for you in one cleaner step.
More information about the Python-list