私はここに与えられた答えを実装しようとしています:
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')
次のエラーが表示されます。
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
私は明らかに間違ったことをしていますか?