「output.txt」の作り方について質問があります。word と prob(l.19) の両方の結果を「output.txt」ファイルに書き込みたいと思います。「model_file.write(word, prob)」と書くと、端末は「TypeError: 関数は正確に 1 つの引数をとります (2 つ与えられます)」というメッセージで私を叱ります。さらに引数を追加しようとしましたが、うまくいきませんでした..誰か私の質問を手伝ってくれませんか??
これは単語 COUNT.PY ですtotal_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()
#