I have two Python modules:
one.py; andtwo.py
I want to change X global variable in two.py.Script two.py running. After I run one.py
one.py
#!/usr/bin/env python
import two
def main():
two.function("20")
if __name__=="__main__":
main()
two.py
#!/usr/bin/env python
X="10"
def main():
while True:
function()
time.sleep(0.25)
def function(input="00"):
if(input!="00"):
global X
X=input
print "change"
print X
if __name__=="__main__":
main()
console:
sudo python two.py
10
10
10
10
after I run one.py but no change in two.py
two.pywithsudo?two.pyas a separate Python process thanone.pyso you can't really change global variables like that. You'll need some kind of inter-process communication.