gpt4 book ai didi

python - “模块”对象不可调用(Python3)

转载 作者:行者123 更新时间:2023-12-04 19:26:39 25 4
gpt4 key购买 nike

我一直在尝试创建此代码来分析文本中的单词,并根据年份对这些单词在文本中频繁出现的次数进行分类。
创建这样的代码后:

#!/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,它们运行良好。
我不知道如何解决它。谁能帮帮我吗?

最佳答案

在不知道 morphemes.py 和 index_terms.py 的结构的情况下,我假设您需要从这些模块中导入一些可调用对象,而不是尝试调用模块本身,在 lst = idt(mf(file)) 行.
IE。

from morphemes import SomeCallableYouNeed as mf
from index_terms import SomeOtherCallableYouNeed as idt

关于python - “模块”对象不可调用(Python3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70200861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com