我有一个脚本应该在文件中附加一些内容,但它引发了一个错误,我不明白,也不确定它是如何被触发的。
代码如下: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
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]