[BangPypers] magic in datetime module?

Noufal Ibrahim noufal at gmail.com
Fri Apr 3 08:09:38 CEST 2009

I'm not an expert but here's a guess.

import uses the builtin __import__ function. Since you set
__builtins__ to {}, you cannot "import" any modules.
>>> __builtins__ = {}
>>> import subprocess
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: __import__ not found

Are you sure your code runs at all? If you set builtins to {}, you
shouldn't be able to do your first import datetime (doesn't work for
me anyway).

Anyway, if you run your python interpreter in verbose mode, you can
see what all it imports as it does so.
>>> import datetime
dlopen("/usr/lib/python2.5/lib-dynload/datetime.so", 2);
import datetime # dynamically loaded from
>>> now = datetime.datetime.utcnow()
>>> print now.strftime("%m %Y")
dlopen("/usr/lib/python2.5/lib-dynload/time.so", 2);
import time # dynamically loaded from /usr/lib/python2.5/lib-dynload/time.so

The print will fail since it tries to do an import inside strftime


More information about the BangPypers mailing list