The namespace for builtin functions?

Francis Avila francisgavila at yahoo.com
Sun Nov 30 00:35:05 EST 2003


Jay O'Connor wrote in message ...
>Blair Hall wrote:
>
>> Can anyone please tell me how to correctly use a built in function
>> when there is a function of the same name in local scope?
>
>
>
>Save yourself a lot of trouble, just give it a different name.
>

This is the best advice.

However...

I don't understand why in __main__, the name __builtins__ refers to the
module object __builtin__, but in any other namespace, __builtins__ is the
__dict__ of __builtin__!

E.g.:
--- a.py ---
a = lambda: __builtins__
--- END ---

>>> __builtins__
<module '__builtin__' (built-in)>
>>> id(__builtins__)
6577648
>>> id(__builtins__.__dict__)
6584048
>>> import a
>>> id(a.a())
6584048

Why not 6577648?!
--
Francis Avila





More information about the Python-list mailing list