Yes, Russell, what you suggested works.

I have to chew more on the syntax to see how this is working.

because in the book that I have, it says:

    exec code [ in globaldict [, localdict] ]

...

--
It's me


"Russell Blau" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >
> > In REXX, for instance, one can do a:
> >
> >     interpret y' = 4'
> >
> > Since y contains a, then the above statement amongs to:
> >
> >     a = 4
> >
> > There are many situations where this is useful.   For instance, you
might
> be
> > getting an input which is a string representing the name of a variable
and
> > you wish to evaluate the expression (like a calculator application, for
> > instance).
>
> In Python, the canonical advice for this situation is, "Use a dictionary."
> This has a number of advantages, including keeping your user's namespace
> separate from your application's namespace.  Plus it's easier to debug and
> maintain the code.
>
> But, if you absolutely, positively have to refer to your variable
> indirectly, you could do:
>
> exec "%s = 4" % y
>
> If y refers to the string "a", this will cause the variable a to refer to
> the value 4.
>
> -- 
> I don't actually read my hotmail account, but you can replace hotmail with
> excite if you really want to reach me.
>
>


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to