【发布时间】:2020-08-14 15:37:03
【问题描述】:
这是输入:
inp = input("Enter the file name: ")
count = 0
try:
x = open(inp)
except:
print("This won't work")
quit()
for line in x:
count += 1
print("There are", count, "lines in", inp)
这是输出
NameERROR: name 'quit' is not defined
quit()、exit()、os._exit()、sys.exit(),没有任何效果。我想它不在库中,我在哪里可以下载包含quit()函数的模块?
【问题讨论】:
-
要使用
os或sys,您首先需要import他们。 -
您的代码对我有用。
quit()和exit()是内置的。如果你想使用sys.exit(),你必须先import sys。没有os.exit()。 -
请在发布问题之前搜索堆栈溢出以查找类似错误。有类似的问题有答案。检查此链接 [stackoverflow.com/q/45066518/9010467]
标签: python