[Python-porting] Strange behavior of eval() in Python 3.1
ben.bob at gmail.com
Sun Aug 29 17:16:35 CEST 2010
> Note that this specific issue only appears because you're using eval().
> For static code, your access to "a" outside of the comprehension's scope
> will be recognized and a proper closure generated.
Thank you very much for your explanation and now I have a real problem
to fix for my Python extension module. More specifically, I call
"eval(expression, module_dict, user_dict)" to evaluate expressions in
user_dict. However, to evaluate expressions such as "[a[x] for x in
a]", I would need "eval(expression, user_dict, user_dict)" to make 'a'
available in globals. But then I do not have access to names in
module_dict, and simple expressions such as 'len(a)' would fail
because I am doing all these from the C/C++ level and there is no
__builtins__ in user_dict.
Happy python-porting, :-)
More information about the Python-porting