[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] setting + modifying a variable for use across the entire application



"""
I'm not sure that works as you expect, though perhaps I've misunderstood what you're doing. Have a look at this and see what you think.

Note file2.x stays as 1, but config.mutated changes to 2

c.m reset file1
1
1
c.m incd file3
1
f1 2
f2 2
f3 2
"""
#__main__
import file1 as a
import file2
print(file2.x)
import file1 as b
print(file2.x)
import file3 as c
print(file2.x)
print("f1 "+str(a.config.mutated))
print("f2 "+str(b.config.mutated))
print("f3 "+str(c.config.mutated))

#config.py
blah="blah"
#file1/3
import config
try:
 if(config.mutated):
  print ("c.m incd "+ __name__)
  config.mutated+=1
except:
 config.mutated=1
 print ("c.m reset "+ __name__)
#file2
import config
x=config.mutated
#file1/3
import config
try:
 if(config.mutated):
  print ("c.m incd "+ __name__)
  config.mutated+=1
except:
 config.mutated=1
 print ("c.m reset "+ __name__)