[Tutor] __builtins__

greg whittier greg at thewhittiers.com
Tue Feb 10 01:59:48 CET 2009


I'm trying to use sparkplot from sparkplot.org as a module.  It's normally
run from the command line and acts on an input file.  I'd like to use it as
a module though to render png's for a web application.

Anyway, if I try "import sparkplot" from the interpreter, I get

>>> import sparkplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sparkplot.py", line 14, in <module>
    min = __builtins__.min
AttributeError: 'dict' object has no attribute 'min'

The offending portion of sparkplot.py appears to be

from pylab import *

# Avoid name collisions with min and max functions from numarray module
min = __builtins__.min
max = __builtins__.max

If I run python sparkplot.py (executing from __main__ namespace?) from the
command line it works as __builtins__ appears to a name for the __builtin__
module and the __builtins__.min reference works, but when I "import
sparkplot," the __builtins__ in the sparksplot module is a dict and
__builtins__.min fails.  In fact changing the above to min =
__buitlins__['min'] eliminates the error on "import sparkplot."

I think the practical answer is to clean up the namespace in sparkplot.py
(get rid of the from pylab import *) as I was planning to do anyway, but I'm
wondering what's behind this __builtins__ behavior.

Thanks,
Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090209/d1e1e3ef/attachment.htm>


More information about the Tutor mailing list