我有一个问题要制作“output.txt”。我想将 word 和 prob(l.19) 结果写入“output.txt”文件。当我写“model_file.write(word, prob)”时,终端用“TypeError:函数只需要 1 个参数(给定 2 个)”消息责骂我。我试图添加更多的论点,但没有奏效..有人可以帮我解决我的问题吗?
这是一个字数.PYtotal_count = 0
train_file = open(sys.argv[1],"r")
for line in train_file:
words = line.strip().split(" ")
words.append("</s>")
for word in words:t
counts[word] = counts.get(word, 0) + 1
total_count = total_count + 1
model_file = open('output.txt',"w")
for word, count in sorted(counts.items(),reverse=True):
prob = counts[word]*1.0/total_count
print "%s --> %f" % (word, prob)
model_file.write(word, prob)
model_file.close()
#