main.py:
import sys
sys.path.append('Pygame Projects')
import sub
from sub import *
loop = True
while loop:
print_hello()
true_the_another_loop()
while anotherLoop:
print_world()
sub.py:
def true_the_another_loop():
loop = False
anotherLoop = True
def print_hello():
print "hello"
def print_world():
print "world"
当我运行main.py时,它只打印"hello"
。为什么"world"
没有打印?
在true_the_another_loop()
中,行loop = Flase
似乎无效。
答案 0 :(得分:0)
您需要返回这些变量的新值。因为它们只是局部变量,所以它们仅限于该函数。您需要将其值传递给其他变量。
...
while loop:
print_hello()
loop, anotherLoop = true_the_another_loop()
...
def true_the_another_loop():
loop = False
anotherLoop = True
return [loop,anotherLop]