I want to be able to import multiple instances of a module and call each by a unique name and it doesn't appear at first glance that either import or __import__ have what I need. I need this because of computing platform I have developed where users write python scripts to do some analysis of science problems where they call modules that have code for monipulating data and where the imported module does some specific scientfic manipulation of data. The key problem is that the module might locally store some partial results ready for the next time its called to save CPU time (typically the results for one timestep ready for the next timestep). But if the module is called for two different purposes in two different parts of the script then the second call will actually see the partial results from the 1st call and vice versa. The simple solution is if it were possible to import the same module file twice but for them to act like they were different modules. It was also make it easy to parallelise code without the called module needing to be thread safe (each instance would be one thread) but that is a lesser priority for the moment.

If I have module in a file called stuff.py has in it a global variable somevariable I want to be able to import multiple instance (with seperate name spaces etc) of stuff so that I could have for example

a=instance1ofstuff.somevariable
b=instance2ofstuff.somevariable

and a and b are referring to different variables in entirely different modules. IS there any way to do this?


====================================================================
Prof Garry Willgoose,
Australian Professorial Fellow in Environmental Engineering,
Director, Centre for Climate Impact Management (C2IM),
School of Engineering, The University of Newcastle,
Callaghan, 2308
Australia.

Centre webpage: www.c2im.org.au

Phone: (International) +61 2 4921 6050 (Tues-Fri AM); +61 2 6545 9574 (Fri PM-Mon) FAX: (International) +61 2 4921 6991 (Uni); +61 2 6545 9574 (personal and Telluric)
Env. Engg. Secretary: (International) +61 2 4921 6042

email:  garry.willgo...@newcastle.edu.au; g.willgo...@telluricresearch.com
email-for-life: garry.willgo...@alum.mit.edu
personal webpage: www.telluricresearch.com/garry
====================================================================
"Do not go where the path may lead, go instead where there is no path and leave a trail"
                          Ralph Waldo Emerson
====================================================================





_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to