我试图在另一个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
中,我正在尝试以下操作:
我也试过了
indexing()
但还是不行。上面写着AttributeError:'module' object has no attribute indexing
。我做错什么了?在
您导入了模块,而不是模块中包含的class对象。在
使用:
或导入类:
^{pr2}$Python styleguide建议模块名称只使用小写字母_和下划线,类名使用CamelCase;这有助于避免混淆模块和类。在
为了遵守样式指南,重命名模块和类;模块名可以是
news_lucene
,类名NewsLucene
。在我注意到整个类只包含静态方法。如果这是该类的唯一目的,则需要将该类全部删除。把所有的东西都变成一个顶层函数。Python不是Java,如果对您手头的问题没有意义的话,您根本不需要使用类。在
相关问题 更多 >
编程相关推荐