AttributeError:“module”对象没有属性索引

2024-10-05 13:36:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在另一个python脚本ProcesosContinuos.py中使用某个python news_Lucene.py脚本的所有函数。我有下面的news_Lucene.py的结构,我要在我的ProcesosContinuous.py中导入它。在

news_Lucene()的代码:

class news_Lucene():

    @staticmethod
    def indexing():
         #some code

    @staticmethod
    def get_set_terms(reader):
         #some code

    @staticmethod
    def get_TFIDF():
         #some code

    @staticmethod
    def get_author_TFIDF():
         #some code
#SOME CODE OUTSIDE STATIC METHODS 

ProcesosContinuous.py中,我正在尝试以下操作:

^{pr2}$

我也试过了

indexing()

但还是不行。上面写着AttributeError:'module' object has no attribute indexing。我做错什么了?在


Tags: 函数py脚本getdefcodesome结构
1条回答
网友
1楼 · 发布于 2024-10-05 13:36:31

您导入了模块,而不是模块中包含的class对象。在

使用:

news_Lucene.news_Lucene().indexing()

或导入类:

^{pr2}$

Python styleguide建议模块名称只使用小写字母_和下划线,类名使用CamelCase;这有助于避免混淆模块和类。在

为了遵守样式指南,重命名模块和类;模块名可以是news_lucene,类名NewsLucene。在

我注意到整个类只包含静态方法。如果这是该类的唯一目的,则需要将该类全部删除。把所有的东西都变成一个顶层函数。Python不是Java,如果对您手头的问题没有意义的话,您根本不需要使用类。在

相关问题 更多 >

    热门问题