Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从WordNet NLTK中提取所有附属形容词并将其保存到文本文件中?_Python_Nltk_Wordnet - Fatal编程技术网

Python 如何从WordNet NLTK中提取所有附属形容词并将其保存到文本文件中?

Python 如何从WordNet NLTK中提取所有附属形容词并将其保存到文本文件中?,python,nltk,wordnet,Python,Nltk,Wordnet,我试图从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_c

我试图从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  

如何将形容词保存到文本文件中?提前谢谢

该错误与编码错误和
str()

改为:

for x in sat_adjectives:
    fo.write(bytes("%s\n" % x, 'UTF-8'))

你能提供整个追踪吗?哪一行导致了TypeError?我很肯定可以:消息文件名行位置回溯C:\Users\Nora\Documents\module1.py 37提取\u sat\u形容词C:\Users\Nora\Documents\module1.py 32 TypeError:“str”不支持缓冲区接口您知道哪一行触发了异常吗?没有指定行。我认为这是因为列表中的项目不是字符串,因此无法写入文本文件。。但我不确定..我们问的是源代码中的行。第32行是哪一行?
for x in sat_adjectives:
    fo.write(bytes("%s\n" % x, 'UTF-8'))