Я пытаюсь реализовать ответ, данный здесь:Inplace файла - окна ошибка
https://stackoverflow.com/a/1388570/1461850
У меня есть входной файл zzz.txt
, содержащие:
potato potato potato potato potato potato potato potato potato
potato potato potato
potato potato potato potato potato potato potato potato potato
potato potato potato potato turnip potato
potato potato parsnip potato potato potato
Я пытаюсь заменить слова в таком месте:
import fileinput
fileinput.close()
file = open('zzz.txt', "r+")
for line in fileinput.input(file, inplace=1):
print line.replace('turnip', 'potato')
I ge t погрешность:
Traceback (most recent call last):
File "testss.py", line 19, in <module>
for line in fileinput.input(file, inplace=1):
File "c:\python27\lib\fileinput.py", line 253, in next
line = self.readline()
File "c:\python27\lib\fileinput.py", line 322, in readline
os.rename(self._filename, self._backupfilename)
WindowsError: [Error 123] The filename, directory name, or volume label syntax i
s incorrect
Я делаю что-то явно не так?