小编zil*_*lox的帖子

Python FileNotFound

我对python很新.

我正在尝试创建一个脚本,它将读取数独的解决方案并阻止它们是否正确.

我需要的东西:

1]提示用户输入包含数独数字的文件/文件路径.它是一个包含9行和9列的.txt文件.仅包含数字.

2]有一些错误处理.

3]然后,如果数独有效,我应该使用与原始输入文件相同的格式创建一个新的文本文件,前缀为"Correct_"

我还没有完全完成程序,但是当我输入错误的路径或文件名时,我收到此错误.

 Hello to Sudoku valitator,

 Please type in the path to your file and press 'Enter': example.txt #This is a non existing file, to test the Error Exception
    'Traceback (most recent call last):
  File "C:/Users/FEDROS/Desktop/bs.py", line 9, in <module>
    sudoku = open(prompt, 'r').readlines()
FileNotFoundError: [Errno 2] No such file or directory: 'example.txt'
Run Code Online (Sandbox Code Playgroud)

这是我的脚本:

while True:
    try:
        prompt = input("\n Hello to Sudoku valitator,"
    "\n \n Please type in the path to your file and …
Run Code Online (Sandbox Code Playgroud)

exception-handling file-not-found python-3.x

7
推荐指数
1
解决办法
6万
查看次数