Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63516
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!panix!panix2.panix.com!not-for-mail |
|---|---|
| From | roy@panix.com (Roy Smith) |
| Newsgroups | comp.lang.python |
| Subject | Re: Recover handle to shadowed builtin? |
| Date | 8 Jan 2014 15:15:25 -0500 |
| Organization | PANIX -- Public Access Networks Corp. |
| Lines | 37 |
| Message-ID | <lakbkt$n27$1@panix2.panix.com> (permalink) |
| References | <mailman.5194.1389210743.18130.python-list@python.org> |
| NNTP-Posting-Host | panix2.panix.com |
| X-Trace | reader1.panix.com 1389212125 6370 166.84.1.2 (8 Jan 2014 20:15:25 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Wed, 8 Jan 2014 20:15:25 +0000 (UTC) |
| Xref | csiph.com comp.lang.python:63516 |
Show key headers only | View raw
In article <mailman.5194.1389210743.18130.python-list@python.org>, Roy Smith <roy@panix.com> wrote: >I'm working with ipython's pylab mode, which replaces the builtin sum() = >with the one from numpy: >[...] >Is there any way to recover a reference to the builtin sum()? Sigh. I figured this out myself. What you want is __builtins__.sum ... 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"] ======================================================== $ ipython Python 2.7.3 (default, Aug 1 2012, 05:14:39) Type "copyright", "credits" or "license" for more information. IPython 0.12.1 -- An enhanced Interactive Python. [...] In [1]: type(__builtins__) Out[1]: module ======================================================== $ ipython --pylab Python 2.7.3 (default, Aug 1 2012, 05:14:39) Type "copyright", "credits" or "license" for more information. IPython 0.12.1 -- An enhanced Interactive Python. [...] In [1]: type(__builtins__) Out[1]: dict ======================================================== I am slowly coming to the conclusion that the best way to deal with pylab is to not use it. Overwriting sum() with a different sum() I can accept, as a useful shortcut. Overwriting __builtins__ seems like wanton vandalism of the namespace.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Recover handle to shadowed builtin? Roy Smith <roy@panix.com> - 2014-01-08 14:52 -0500
Re: Recover handle to shadowed builtin? roy@panix.com (Roy Smith) - 2014-01-08 15:15 -0500
Re: Recover handle to shadowed builtin? Chris Angelico <rosuav@gmail.com> - 2014-01-09 09:22 +1100
csiph-web