Gabor Urban wrote:
Hi guys,
2. We have tp write a module that will be imported a couple of places. Though we must be sure, this module's initialization is performed only once. How can we implement this? I do not know what to google for.....
There are two ways to have one file executed twice to create two module objects with two different names. 1) run it as the main file and also import it; 2) import with sufficiently different import statements. (I do not know all the ways to 'accomplish' the latter, but I know it can be done.)
So, if you do not execute that module as the main script and you use the exact same import statement everywhere, so that the resulting module is given the exact same name, then it will be created once and subsequent imports will return the same object. This is the normal situation. The two cases above are typically accidents.
If you have doubts, put print("Hello, module xxx being initialized.") at the top of the module.
tjr -- http://mail.python.org/mailman/listinfo/python-list