February 16th, 2005, 09:01 AM
Globals between moduls?
The functionality of my main program is like this:
dataLock = threading.RLock()
com = com_base.comtype('com') #Create thread that handles communication
Now, in my com module I want to use dataLock, how do I get access to it? It all worked when everything was in one module but now it says that dataLock is undefined (which i understand) but how do I import datalock to com??
"from main import dataLock" does not work for me
February 16th, 2005, 03:04 PM
You seem to be on the right track anyway: using the from-module-import statement. If you want to import from __main__ then you need to change main to __main__ in your import statement.
Still, importing something into a module from __main__ seems like a bad idea to me. Personally I would put the variables definition inside the com module and then import it into the __main__ program.
Note: that you don't need to define your variable as being global since it is being defined in the global namespace i.e.
You also seem to be overwriting the com module with your own variable named com.
>>> global a
>>> a = 1
>>> b = 2
>>> def h():
>>> def i():
Hope this helps,
February 17th, 2005, 02:53 AM
Of course, now it works fine. Thank you Mark!
Originally Posted by netytan