Recover handle to shadowed builtin?

Chris Angelico rosuav at gmail.com
Wed Jan 8 17:22:52 EST 2014


On Thu, Jan 9, 2014 at 7:15 AM, Roy Smith <roy at panix.com> wrote:
> BUT, not only does pylab overwrite sum(), it overwrites __builtins__
> as well!  Instead of a module, it's now a dict.  You can still get at
> the builtin sum, but you need to do __builtins__["sum"]

That probably means that it _only_ overrides the one from
__builtins__, which is the easiest way.

You're talking about something that's done at the interactive prompt.
It should be possible to play with sitecustomize.py to snapshot your
original builtins. Try this (untested):

# sitecustomize.py
import builtins
import sys
sys.original_builtins = builtins
sys.original_sum = sum


(or use __builtins__ or __builtin__ or whatever's appropriate for your version)

If snapshotting all of builtins doesn't work, snapshotting just sum
should. The key is executing code before pylab does its overwriting.

ChrisA



More information about the Python-list mailing list