所以我试图将我自己的python模块导入到我编写的新脚本中。我收到错误:
AttributeError:'module'对象没有属性'getSessionIds'
在我的主文件中,我正在导入:
import UnityAppSessionSummary
class ScheduledGenSummaries(DatabaseModule):
def __init__(self):
super(ScheduledGenSummaries, self).__init__()
def run(self):
... (some db connection stuff)
sessionIds = UnityAppSessionSummary.getSessionIds(db, user)
if __name__ == '__main__':
testrun = ScheduledGenSummaries()
testrun.run()
在我的UnityAppSessionSummary.py文件中,我有这样的东西:
class UnityAppSessionSummary():
# This method is used to obtain a list of all session ID's for a certain user
def getSessionIds(self, db, user):
....code....
我不知道为什么我会收到此错误,而且我已查看过其他帖子。我已经尝试'导入UnityAppSessionSummary作为应用'然后应用。(UnityAppSessionSummary中的某些功能),但它仍然给我错误。提前谢谢。
答案 0 :(得分:2)
您运行
时正在导入文件UnityAppSessionSummary.py
import UnityAppSessionSummary
但是,在.py
文件中,您还有一个名为UnityAppSessionSummary
的类,而内部是您的getSessionIds()
方法。试试这个:
from UnityAppSessionSummary import UnityAppSessionSummary as app
# ...
sessionIds = app.getSessionIds(db, user)