我是蟒蛇新手。有一个带有我想使用的方法(getService)的python类
class ServicesManager
def __init__(self, logger):
...initialize stuff
def getService(self, name):
... do some stuff
def anotherMethod():
... do more stuff
从另一个班级这就是我所说的
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
我做错了什么?这些类位于单独的文件中