我正在尝试确定文件是否存在,作为 Python 3.7.2 中错误处理过程的一部分。os.path.isfile()然而,作为我尝试使用的过程的一部分,我似乎在 if 语句中遇到了语法错误。
我该如何解决这个问题,以便正确读取?
代码是:
import sys
import os
import random
import time
while True:
try:
user_input = input("Enter the path of your file (Remember to include the file name and extension): ") # Imports user defined file
if os.path.isfile(user_input) == False:
print("I did not find the file at, "+str(user_input) # Checks if file is present
continue
else:
break
编辑:包括错误类型
长风秋雁
临摹微笑
慕村225694
相关分类