Is there any declaration or defintion has to be done in the Sample1 and Sample2 modules?
- PSB
- PSB
# test.py
# class holds globals
import inspect # just for testing this idea
def PrintGlobRep():
for member in inspect.getmembers(globRep):
if not member[0].startswith('_'):
print member
class GlobalRepository:
globalList = []
globalInt = 5
globRep = GlobalRepository()
# module1 uses Global Repository from test.py import test # this does initialization of the Global Repository from test import globRep # get the class instance test.PrintGlobRep() globRep.newGlobal = 12 test.PrintGlobRep()
Main.py
from Sample1 import CSample1
from Sample2 import CSample2
from Sample1 import iVar
from Sample2 import iVar
iVar = 1
if __name__ == '__main__':
obj1 = CSample1()
obj2 = CSample2()
obj1.Func1()
obj2.Func4()
print iVar
Sample1.py
class CSample1:
def Func1(self):
global iVar
iVar = 20
print iVar
def Func2(self):
pass
iVar = CSample1()
Sample.2py
class CSample2:
def Func3(self):
pass
def Func4(self):
global iVar
print iVar
iVar = CSample2()
Main.py
from Sample1 import CSample1
from Sample2 import CSample2
from Sample1 import iVar
from Sample2 import iVar
iVar = 1
if __name__ == '__main__':
obj1 = CSample1()
obj2 = CSample2()
obj1.Func1()
obj2.Func4()
print iVar
Sample1.py
class CSample1:
def Func1(self):
global iVar
iVar = 20
print iVar
def Func2(self):
pass
iVar = CSample1()
Sample.2py
class CSample2:
def Func3(self):
pass
def Func4(self):
global iVar
print iVar
iVar = CSample2()
# Main.py
try:
reload(Sample1)
except:
import Sample1
try:
reload(Sample2)
except:
import Sample2
iVar = 1
if __name__ == '__main__':
obj1 = Sample1.CSample1()
obj2 = Sample2.CSample2()
print iVar
iVar = obj1.Func1()
print iVar
iVar = obj2.Func4()
print iVar
# Sample1.py
class CSample1:
def Func1(self):
iVar = 40
return iVar
def Func2(self):
pass
# Sample.2py
class CSample2:
def Func3(self):
pass
def Func4(self):
iVar = 20
return iVar
try:
reload(Sample1)
except:
import Sample1
try:
reload(Sample2)
except:
import Sample2
iVar = 1
if __name__ == '__main__':
obj1 = Sample1.CSample1()
obj2 = Sample2.CSample2()
print iVar
iVar = obj1.Func1()
print iVar
iVar = obj2.Func4()
print iVar
print Sample1.iVar
# Sample1.py
class CSample1:
def Func1(self):
global iVar
iVar = 40
return iVar
def Func2(self):
pass
a = CSample1()
a.Func1()
Comment