【发布时间】:2015-06-29 19:35:58
【问题描述】:
我正在尝试从 WordNet 中提取所有附属形容词同义词集并将它们保存到文本文件中。请注意,卫星形容词在同义词集名称中表示为“s”,例如“(fantastic.s.02)”。以下是我的代码:
def extract_sat_adjectives():
sat_adj_counter = 0
sat_adjectives = []
for i in wn.all_synsets():
if i.pos() in ['s']:
sat_adj_counter +=1
sat_adjectives = sat_adjectives + [i.name()]
fo = open("C:\\Users\\Nora\\Desktop\\satellite_adjectives.txt", "wb")
for x in sat_adjectives:
fo.write("%s\n" % x)
fo.close()
extract_sat_adjectives()
我得到的错误是:
TypeError: 'str' does not support the buffer interface
如何将形容词保存到文本文件中?提前致谢。
【问题讨论】:
-
你能提供整个 Traceback 吗?哪一行导致 TypeError?
-
我当然可以:消息文件名行位置回溯
C:\Users\Nora\Documents\module1.py 37 extract_sat_adjectives C:\Users\Nora\Documents\module1.py 32 TypeError : 'str' 不支持缓冲接口 -
你知道是哪一行触发了异常吗?
-
没有指定行。我认为这是因为列表中的项目不是字符串,因此无法写入文本文件..但我不确定..
-
我们在询问源代码中的这一行。第 32 行是哪一行?