我是一個蟒蛇新手。有與我想要使用如何在類python中從類B調用類A中的方法?我收到「自己沒有定義」
class ServicesManager
def __init__(self, logger):
...initialize stuff
def getService(self, name):
... do some stuff
def anotherMethod():
... do more stuff
從另一個類的方法(的getService)Python類,這是如何我叫它
from ServicesManager import ServicesManager
class serviceCaller:
def __init__(self, logger):
self.logger = logger
self.sm = ServicesManager(self.logger)
myService = self.sm.getService('serviceA')
但是當我執行它,我收到
Traceback (most recent call last):
File "./serviceCaller.py", line X, in <module>
class serviceCaller:
File "./serviceCaller.py", line Y, in serviceCaller
myService = self.sm.getService('serviceA')
NameError: name 'self' is not defined
我會做什麼錯?該班是分隔的文件