I have written the odd handy function while I’ve been doing python. (A few methods on lists, couple of more useful input functions ect.)
What I want is to be able to access these functions from a python file without having to import a module through import my_module.
The way I though it would happen is automatically importing a module, or putting these functions in another default python module, but I don’t really mind how it’s done.
Can anyone shed some light on how I should do this?
(I know import my_module is not a lot, but you could end up with
sys.path.append("c:\fake\path")
from my_module import *
which is getting long…)
The python module
siteis imported automatically whenever the python interpreter is run. This module attempts to import another, namedsitecustomize. You could put your functions in there, adding them to the__builtins__mapping with:Note that this only works on cpython, where
__builtins__is a mutable dict. Doing so will automatically make these functions available to all your python code for this installation.I strongly would discourage you from doing so! Implicit is never better than explicit, and anyone maintaining your code will wonder where the hell these came from.
You’d be better off with a
from myglobalutils import *import in your modules.