我有一个班级
class worker:
def __init__(self, mainProject, victims):
self.mainProject = mainProject
self.victims = victims
def mainWork(self, mainProject, victims):
...
def send(self):
...
在 mainWork()中我定义了一些变量,浏览器对象和其他数据,我需要将它们转移到 send()
答案 0 :(得分:1)
只需在self
中分配和阅读您想要的内容:
def mainWork(self, mainProject, victims):
self.whatever = 42
def send(self):
print self.whatever
答案 1 :(得分:1)
做这样的事情: -
class worker:
def __init__(self, mainProject, victims):
self.mainProject = mainProject
self.victims = victims
def send(self):
print self.mainProject, self.victims
def main():
w = worker('programming', 'Jess')
w.send()
if __name__ == '__main__':
main()