I have a python script with a function and a while loop and I want to call this function from another python script which also has a while loop. Here is an example script:
script1.py:
global printline
printline = abc
def change(x):
global printline
printline = x
while True:
global printline
print printline
And this is script2.py:
from script1 import change
change(xyz)
while True:
print hello
When I run script2.py, it starts to print abc and doesn't go into the while loop in this script.
When I run script1.py, it prints abc.
When I run both together, in different terminals, both print abc.
I need it so that when both scripts are run, script2.py can change the variable printline while going into the while loop.
I don't know if this is the right way to do it as I'm new to python.
Thanks.
abcandxyz? Please post the actual code you are having trouble with, verbatim, otherwise all anyone can do is guess.printlinevariable? As in, when both scripts run at the same time, they share the sameprintlinevariable?abcandxyzsupposed to be strings"abc"and"xyz"?globalstatement outside a function.while True:code inscript1.pyexecutes, and it never gets out of that infinite loop. Top-level statements in a module file are just expected to initialize the module, they need to finish.