Creating True Global Functions by Modifying Builtins
peter at engcorp.com
Wed Jun 9 20:04:01 CEST 2004
> I really, really want a handful of 'true' global functions, ones that
> can be called from anywhere without requiring importing.
No, you don't. ;-)
Really, why bother when with a simple "import kamilche_tools" (or
whatever you want), you can get access to all your stuff without
hiding it from everyone, thereby making maintenance much harder?
The only time I've found a valid reason to stick stuff in __builtin__
is when trying to make current code *forward compatible* with newer
versions of Python, such as when bool() and True/False where added
in 2.2 (?) and we had to stick with 2.0.
Any other use smells of "slick" programming and is likely to
bite you in the future.
> So I added it to the 'builtins' of Python, and it appeared to work. :-O
The name __builtins__ is apparently an implementation detail.
If that's true, you don't want to use it.
Instead, if you really must, at least "import __builtin__" (note,
no "s" on the end) and use that module.
More information about the Python-list