首页 > 解决方案 > 如何清除“唯一 ID 为 1”和“FileNotFoundError”?

问题描述

运行代码时卡住了。下面显示的文件路径是显示输出的路径,即我正在重命名它。现在,我无法获得输出。

The unique id is 1
Traceback (most recent call last):
  File "F:\ISRO\S_data\codes\Auto.py", line 390, in <module>
    os.rename("C:\\Users\\finol\\Desktop\\ISRO\\Final Program\\OVERVIEW.OUT", str(uniqueid[a][0])) ##The output file is renames with the uniqueid
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\finol\\Desktop\\ISRO\\Final Program\\OVERVIEW.OUT' -> '1'
'''
And this is the part of the code

导入操作系统

os.rename("C:\\Users\\finol\\Desktop\\ISRO\\Final Program\\OVERVIEW.OUT",
          str(uniqueid[a][0]))  ##The output file is renames with the uniqueid
import shutil

shutil.move(str(uniqueid[a][0]),
            "C:\\Users\\finol\\Desktop\\ISRO\\Final Program\\OUTPUT\\")  ##The output file is moved to a seperate directory
a = a + 1

标签: pythonpython-3.x

解决方案


尝试通过将 an 附加r到以下格式的字符串输入路径来获取原始格式的输入路径:

os.rename(r"C:\\Users\\finol\\Desktop\\ISRO\\Final Program\\OVERVIEW.OUT",
      str(uniqueid[a][0]))

我有linux系统,所以我无法在我自己的系统上复制问题,但这应该可以。您也可以更改\\/查看它是否有效。


推荐阅读