[BangPypers] magic in datetime module?

Anand Chitipothu anandology at gmail.com
Fri Apr 3 09:51:07 CEST 2009


2009/4/3 Anand Balachandran Pillai <abpillai at gmail.com>:
> Retracted. I was testing wrong code :) It should be __builtins__,
> not __builtins, in which case it fails...!
>
> However you can do the same thing and inject the __import__
> name after your modification.
>
> Like,
>
> code = generate_code(template)
> __import__ = __builtins__.__import__
> custom_builtins.__import__ = __import__
>
> env = {'__builtins__': custom_builtins}
> exec(code, env)

No need to do

__import__ = __builtins__.__import__

It is already available in builtins.  Adding __import__ to
custom_builtins solves the problem.

But I'm trying to understand this curious behavior.

Anand


More information about the BangPypers mailing list