On Fri, 08 Feb 2008 00:25:14 -0800, loquehumaine wrote: > I have seen that if I type help() at a prompt, and then 'modules', > I'll be given a list of all modules available, thanks to this group.. > But I have seen the differences between them and the one in > dir(__builtins__). > Why are some modules in __builtins__ and others don't ? (UserDict for > example)
`__builtins__` doesn't contain modules:: Python 2.4.4 (#2, Apr 12 2007, 21:03:11) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import inspect >>> inspect.getmembers(__builtins__, inspect.ismodule) [] > Why dir(__builtins__) gives me "math" but not help(__builtins__) ? So there's no 'math' in `__builtins__`:: >>> 'math' in dir(__builtins__) False > What are the differences between __builtins__ and __builtin__ ? (By > the way, I have python 2.4) `__builtins__` is an implementation detail, and `__builtin__` is a name of a module you can import. You should not use `__builtins__` but import `__builtin__` and inspect that instead of `__builtins__`. The (symmetric) difference of the two is empty:: >>> import __builtin__ >>> set(dir(__builtins__)).symmetric_difference(dir(__builtin__)) set([]) > Finally, if I do del(__builtins__), what can I do to repair the > "mistake" (as I got an import error __import__ not found if I want to > import __builtins__...? Don't ``del __builtins__`` in the first place. :-) > That's may be obvious for you, but that's all strange to me and I > didn't find answers on the net... So the real question is, why you see 'math' in `__builtins__`. It should not be there. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list