Python for a PHP user, how do i...?

rw2 richw at
Tue May 15 17:24:33 EDT 2001

In article <9ds48t$1rt$1 at>, "Magnus Lie Hetland"
<mlh at> wrote:

>> >>> spam="print 'eggs'"
>> >>> eval(compile(spam,'<string>','exec'))
>> eggs
>> rw2
> Why the compile? Why not just eval(spam)?

Try it.

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 mailing list