【发布时间】:2019-05-13 19:19:32
【问题描述】:
我有以下代码,它应该询问用户 2 文件名。我在第二个函数中的 input() 出现错误,但在第一个函数中没有,我不明白...... 这是错误:
输出 = getOutputFile() 文件“splitRAW.py”,第 22 行,在 getOutputFile 文件名 = 输入(“\t=>”) TypeError: 'str' 对象不可调用
# Loops until an existing file has been found
def getInputFile():
print("Which file do you want to split ?")
fileName = input("\t=> ")
while 1:
try:
file = open(fileName, "r")
print("Existing file, let's continue !")
return(fileName)
except IOError:
print("No such existing file...")
print("Which file do you want to split ?")
fileName = input("\t=> ")
# Gets an output file from user
def getOutputFile():
print("What name for the output file ?")
fileName = input("\t=> ")
这是我的 main() :
if __name__ == "__main__":
input = getInputFile()
output = getOutputFile()
【问题讨论】:
-
在代码中的某处,您定义了
input = something_here。根据您的 IDE,它可能位于不同的文件或控制台中 -
就是这样,谢谢!!
标签: python input error-handling