[Edu-sig] More on teaching about namespaces
kirby urner
kirby.urner at gmail.com
Wed Sep 13 22:31:09 CEST 2006
> >>> del __builtins__
> >>> dir()
> ['__builtins__', '__doc__', '__name__', 'keyword']
>
> Didn't work. Nothing happens. But the keyword namespace is easy to get rid of:
<wizard type="smartypants">
<comment>
Wrongo, buddy boy!
Something *does* happen when you delete __builtins__.
It sticks around *as a dictionary* named __builtins__, but you've
purged it from the namespace *as a module* -- which is what allowed
dir to treat it as such, and return just a list.
Look below:
>>> ============= RESTART ==============
>>> __builtins__
<module '__builtin__' (built-in)>
>>> type(__builtins__)
<type 'module'>
>>> del __builtins__
>>> type(__builtins__)
<type 'dict'>
>>> del __builtins__
>>> type(__builtins__)
<type 'dict'>
Now if you go dir(__builtins__), it'll just give you the namespace of
a regular dictionary, and if you put __builtins__ on the command line
and press enter, you'll get a dump of that dictionary's contents (an
invocation of its __repr__ method).
</comment>
</wizard>
Thanks a lot Smartypants. I'm sure we'll be seeing *you* here again.
Kirby
More information about the Edu-sig
mailing list