【发布时间】:2022-01-09 00:39:59
【问题描述】:
我一直在尝试创建此代码来分析文本中的单词,并根据年份对这些单词在文本中出现的次数进行分类。 创建这样的代码后:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import morphemes as mf
import index_terms as idt
###############################################################################
def count_yr(counter, filename, index, size):
'''
counter: dictionary (key: word, value: frequency list)
filename : file for analyzing words
index : index for year 2000->0, 2001->1, ...
size : total number of years
'''
word_count = {}
with open(filename, "r") as file:
lst = idt(mf(file))
for word in lst:
counter[word] = [0]*size
for word in lst:
if word in counter:
counter[word][index] += 1
else:
counter[word][index] = 1
return counter
###############################################################################
if __name__ == "__main__":
if len(sys.argv) < 2:
print( "[Usage]", sys.argv[0], "in-file(s)", file=sys.stderr)
sys.exit()
counter = {}
for i, filename in enumerate(sys.argv[1:]):
count_year( counter, filename, i, len(sys.argv[1:]))
while True:
query = input('Please type the word you are looking for (type "exit" to exit): ')
if query == "exit":
break
if query in counter:
print(counter[query])
else:
print("No Result")
好像弹出了"TypeError: 'module' object is not callable"。
我创建了 morphemes.py 和 index_terms.py,它们运行良好。
我不知道如何解决它。谁能帮帮我?
【问题讨论】:
-
您希望调用 模块
index_terms和morphemes做什么?你的意思是from index_terms import idt和from morphemes import mf吗? -
是的,我把它误认为是别的东西了!感谢您指出它们!
标签: python linux file ubuntu module