__builtin__ vs __builtins__?

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Jan 14 04:24:30 EST 2002


rihad <rihad at mail.ru> wrote in 
news:jm654ukcp86ik300i92bo46dbihgka0avc at 4ax.com:

> Hi there, I can't seem to understand the difference between
> __builtin__ and __builtins__.
That is because there is no difference. They are two names for the same 
module. __builtins__ is a variable added to the globals dictionary 
automatically, it almost always refers to the module __builtin__.

> (BTW it looks like all the 115 items can be reference without
> qualification)
That is the point of them.

> 
> Which should be used?
Generally neither. The names in __builtins__ are always in scope so you 
don't need to refer to the module.

The only time you might want to use the module directly would be if you 
wanted to add or remove builtin values, or if you wanted to execute some 
Python with a restricted set of builtins.


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list