eval

Johannes Zellner johannes at zellner.org
Thu Jul 6 19:15:20 EDT 2000


On Thu, 6 Jul 2000, Stuart Ford wrote:

> 
> ----- Original Message ----- 
> From: Johannes Zellner <johannes at zellner.org>
> To: <python-list at python.org>
> Sent: Thursday, July 06, 2000 5:46 PM
> Subject: eval
> 
> 
> > 
> > Hi,
> > 
> > how does eval work ?
> > 
> >     eval('print "fred"')
> > 
> 
> exec not a function in the real sense, but a core command,
> it does not require the use of parentheses. 
> 
> Examples:
> 
> eval 'print "fred"'     will work..
> 
> or 
> 
> command = 'print "fred"'
> exec command                  will work just as well..
> 
> I have used exec to process dynamically written code within the
> current namespace.

ahh. I see. thanks.

And how do I define the scope where exec evaluates ?
E.g.

def generator(x):
  eval 'def '+x+'(y): print "fred"'

and after calling
>>> generator('lola')
I want to be able to use
>>> lola('lolita')

-- 
   Johannes





More information about the Python-list mailing list