Python /編程新手在這裏。Python - 「IOError:[Errno 0] Error」。在我的代碼中觸發這個錯誤是什麼?
我有一個腳本,應該將一些東西附加到文件中,但它是養我不理解和不知道它是如何被觸發的錯誤。
下面是代碼:
import re
num_words = "four kiddiewinks|four children|four kids"
words_list = num_words.split('|')
def append_2synonym(words_list, num_words):
with open('test2 words.txt', 'a+') as f:
read_f = f.read()
patt = r'^' + words_list[0] + '\|'
result = re.search(patt, read_f, re.MULTILINE)
if result == None:
f.write("\n" + num_words)
else:
print "\nNo match found in '2 words.txt' file"
append_2synonym(words_list, num_words)
這裏是 'test2的words.txt' 文件的內容:
five kiddiewinks|five kids|five children
mobile phone|cell phone|cellular phone
stinky cheese|smelly cheese
以下是完整的錯誤我得到:
Traceback (most recent call last):
File "D:\Magic Briefcase\My Python Scripts\Spin Scripts\synonyms\testing2.py", line 16, in <module>
append_2synonym(words_list, num_words)
File "D:\Magic Briefcase\My Python Scripts\Spin Scripts\synonyms\testing2.py", line 12, in append_2synonym
f.write("\n" + num_words)
IOError: [Errno 0] Error
[Finished in 0.1s with exit code 1]
任何幫助表示讚賞 乾杯 達倫
類似於http://stackoverflow.com/questions/11176724/python-file-operations,是您在Windows? –
是的,我使用Windows 7 –