OSError:[WinError 123]文件名,目录名称或卷标签语法不正确:(正在运行脚本)

时间:2019-07-06 06:55:40

标签: python windows

我正在尝试在Windows 10中运行脚本。该脚本应该查看另一个.py文件,并用另一个替换字符。下面是代码:

import fileinput

with fileinput.FileInput("C:\Temp\test_python.py", inplace=True, backup='.bak') as file:
    for line in file:
        print(line.replace('@', ';'), end='')

Traceback (most recent call last):
  File "C:\Temp\test_python.py", line 4, in <module>
    for line in file:
  File "C:\Users\carlos.quirarte\AppData\Local\Programs\Python\Python37\lib\fileinput.py", line 252, in __next__
    line = self._readline()
  File "C:\Users\carlos.quirarte\AppData\Local\Programs\Python\Python37\lib\fileinput.py", line 339, in _readline
    os.rename(self._filename, self._backupfilename)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\Temp\test_python.py' -> 'C:\\Temp\test_python.py.bak'

0 个答案:

没有答案