On Sun, May 10, 2015 at 9:31 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Sun, May 10, 2015 at 7:39 PM, zipher <dreamingforw...@gmail.com> wrote:
>> Similarly, you'd want:
>>
>>>>> encode(codestr)
>>
>> to instantiate all objects in the codestr.  You can't do this with eval, 
>> because it doesn't allow assignment (eval(n=2) returns "InvalidSyntax").
>
> Is exec what you're looking for?
>
>>>> exec('n = 2')
>>>> print(n)
> 2

I just found that eval can be used to evaluate a code object compiled
in the 'exec' mode:

>>> eval(compile('n = 42', '', 'exec'))
>>> n
42

Interesting. But I suppose that the mode is really just a compilation
option and there's not really much distinction as far as eval is
concerned once they've been compiled.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to