这里是我的代码的一部分: -类型错误:使用字典时,“类型”对象未标化,
words_custom=[]
sentence_list=[]
pos_tags=[]
words_posscore={}
words_neg={}
words_pos={}
func_words=[]
def init():
global words_posscore
global words_neg
global words_pos
global func_words
words_posscore={}
with open('words_posscore.csv','r',encoding='utf-8') as f:
reader=csv.reader(f)
for row in reader:
print(type(row))
print(row)
words_posscore[row[0]]=float[row[1]]
with open('negative_words.csv','r',encoding='utf-8') as f:
reader=csv.reader(f)
for row in reader:
words_neg[row[0]]=1
words_pos={}
with open('positive_words.csv','r',encoding='utf-8') as f:
reader=csv.reader(f)
for row in reader:
words_pos[row[0]]=1
with open('Feature/func_words.csv','r',encoding='utf-8') as f:
reader=csv.reader(f)
for row in reader:
func_words.append(row[0])
我收到以下错误: -
Traceback (most recent call last):
File "train.py", line 586, in <module>
init()
File "train.py", line 120, in init
words_posscore[row[0]]=float[row[1]]
TypeError: 'type' object is not subscriptable
虽然我使用words_posscore作为字典并初始化它,我不知道为什么它将它视为一个类型对象而不是字典。
我已经看过回答以下问题: -
TypeError: 'type' object is not subscriptable when indexing in to a dictionary
应该是'float(row [1])' –
做得好,谁downvoted所有(正确)的答案。 –