Slave to master auto linking.
Chris Angelico
rosuav at gmail.com
Sun Nov 13 21:15:05 EST 2011
More information about the Python-list mailing list
Sun Nov 13 21:15:05 EST 2011
- Previous message (by thread): Slave to master auto linking.
- Next message (by thread): my new project, is this the right way?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2011/11/14 Богун Дмитрий <vugluskr at vugluskr.org.ua>: > m = master() > s = m.slave() > s.master is m > Can you simply have m.slave() pass a parameter to the slave's constructor? class Master(object): class Slave(object): def __init__(self,master): self.master=master print 'Slave.__init__: self.master: ', self.master def slave(self): return self.Slave(self) Alternatively, you don't have to nest the classes at all: class Slave(object): def __init__(self,master): self.master=master print 'Slave.__init__: self.master: ', self.master class Master(object): def slave(self): return Slave(self) By passing 'self' to the Slave() constructor, I give the slave a chance to keep a reference to its own master. Chris Angelico
- Previous message (by thread): Slave to master auto linking.
- Next message (by thread): my new project, is this the right way?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list