【发布时间】:2020-02-05 23:40:24
【问题描述】:
我在 Visual Studio Code 中有 2 个文件。 “main.py”和“g_Global.py”。 “g_Global.py”有这个代码:
import msvcrt
def key():
if msvcrt.kbhit() and msvcrt.getch() == chr(27).encode():
u = False
在“main.py”中有:
import g_Global as g
while x.lower() == 'n' and u == True:
g.clear()
print(y)
y = input('Write a line to add. > ')
g.key()
if u == False:
break
...但是当我运行代码时,当我按下“esc”时什么也没有发生。有什么想法吗?
【问题讨论】:
-
这还能运行吗?文件 main 中的代码没有定义
u。编辑:猜猜这对你来说可能是一个剧透警报,如果你是细心的。您的错误是假设gGlobal.py中的key函数中的局部变量u与main.py 中的变量u有任何关系。就因为他们名字一样?不,那不行,它们在不同的命名空间中。 -
@ParitoshSingh u 已定义,每个文件大约有几千行代码,所以我没有费心包括整个 thingymajig
标签: python python-3.x escaping text-editor msvcrt