Re: Method Delegation To Subinstances
I could then fill the getattr function with different conditional statements as needed, cool. Thanks Steve!On 5/27/06, Steve Holden < [EMAIL PROTECTED]> wrote:Cloudthunder wrote:> In the example:> > class Boo:> def __init__(self, parent):> self.parent = parent> print self.parent.testme> def run():> print "Yaho!">> class Foo: > testme = "I love you!"> def __init__(self):> test = Boo(self)>> A = Foo()>>> How can I set up method delegation so that I can do the following: >> A.run()>> and have this call refer to the run() method within the boo instance?> Also, what if I have tons of functions like run() within the boo> instance and I want all them to be directly accessible as if they were > part of their parent (the Foo instance)?>The usual way is to provide a __getattr__ method, since this is invokedafter the usual mechanisms have failed to produce a sought attribute.class Boo: def run(self): print "Yaho!" def identify(self):print repr(self)class Foo: testme = "I love you!" def __init__(self): self.test = Boo() def __getattr__(self, attname): return getattr(self.test, attname)A = Foo()B = Boo()B.run()B.identify()A.run()A.identify()[EMAIL PROTECTED] ~/Projects/Python $ python test49.pyYaho!<__main__.Boo instance at 0x186c002c>Yaho!<__main__.Boo instance at 0x186b9d4c>regards Steve--Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.comLove me, love my blog http://holdenweb.blogspot.comRecent Ramblings http://del.icio.us/steve.holden--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Accessing object parent properties
I have two classes. I later create instances. One class creates an instance of the other class within itself. My question, is how does the child access the parent's properties, since it doesn't know ahead of time that it's going to be "adopted"? Example: class Boo: passclass Foo: X = 1 __init__(self): self.test = boo()How in this case does the boo instance (self.test) access variable X? I need to write a function in the Boo class that assume the Boo instance is going to be instantiated within another class instance which will have certain variables it needs to access. How do I do this? Am I making sense? Thank you to anyone who can help.- Cloudthunder -- http://mail.python.org/mailman/listinfo/python-list
Method Delegation To Subinstances
In the example:class Boo: def __init__(self, parent): self.parent = parent print self.parent.testme def run(): print "Yaho!"class Foo: testme = "I love you!" def __init__(self): test = Boo(self)A = Foo()How can I set up method delegation so that I can do the following:A.run()and have this call refer to the run() method within the boo instance? Also, what if I have tons of functions like run() within the boo instance and I want all them to be directly accessible as if they were part of their parent (the Foo instance)? -- http://mail.python.org/mailman/listinfo/python-list
Re: Method Delegation To Subinstances
In the example:class Boo: def __init__(self, parent): self.parent = parent print self.parent.testme def run(): print "Yaho!" class Foo: testme = "I love you!" def __init__(self): test = Boo(self)A = Foo()How can I set up method delegation so that I can do the following:A.run()and have this call refer to the run() method within the boo instance? Also, what if I have tons of functions like run() within the boo instance and I want all them to be directly accessible as if they were part of their parent (the Foo instance)? -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing object parent properties
In the example:class Boo: def __init__(self, parent): self.parent = parent print self.parent.testme def run(): print "Yaho!" class Foo: testme = "I love you!" def __init__(self): test = Boo(self)A = Foo()How can I set up method delegation so that I can do the following:A.run()and have this call refer to the run() method within the boo instance? Also, what if I have tons of functions like run() within the boo instance and I want all them to be directly accessible as if they were part of their parent (the Foo instance)? Thanks!On 5/23/06, Max Erickson <[EMAIL PROTECTED]> wrote: One way:class Boo:def __init__(self, parent):self.parent=parent class Foo:X=1def __init__(self):self.test=boo(self)--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Rapyd: control variables
Okay, I'm just starting out with rapyd, so bear with me. I have one form and a label and I gave the label a controlvariable (textvariable). See:#--# # ## testme ## # #--#class testme(Frame): def __init__(self,Master=None,**kw): self.MyName = StringVar() self.MyName = str(type(ClassKernelBasic)) apply(Frame.__init__,(self,Master),kw) self.MyLabel = Label(self,text='replace me!',textvariable=self.MyName) self.MyLabel.pack(side='top') # #Start of event handler methods # # #Start of non-Rapyd user code #In the main file I imported my module (classkernelbasic) where the comment told me to and it seemed to have no problem importing. But when I run the app, nothing shows up in the label or, if something does, it's whatever I put in the label widget's "text" variable. I also tried setting the text variable to MyName, but this also failed to display anything. What's wrong? -- http://mail.python.org/mailman/listinfo/python-list
Merging Objects
Question: how do I merge two objects? I would like to be able to have an instance of Foo and an instance of Boo and then be able to add them together and create a new object that has the methods and properties of both objects. I am going to be doing a lot of this and I don't want to have to dynamically (or otherwise) create a whole bunch of classes that inherit from both Foo and Boo then create instances of those new children classes. In fact, this wouldn't work for me anyway because I am going to have an instance of Foo which will be used within my algorithm for sometime then later I will want to merge it with a fresh instance of Boo or otherwise give it all the methods and properties of the Boo class. Am I making any sense here? Thanks. - OPP.S. I also noticed that we can no long use the __members__ property to get a tuple of all a class's methods. How can I get the same info from dir()? Dir(), I understand, tells you about all properties and you can't tell it to just list the methods. -- http://mail.python.org/mailman/listinfo/python-list
Re: Merging Objects
Sorry, I don't understand, how does this solve my problem?On 4/3/06, Jesus Rivero - (Neurogeek) <[EMAIL PROTECTED] > wrote:-BEGIN PGP SIGNED MESSAGE-Hash: SHA1>>> help(getattr) help(setattr) Regards, Jesus Rivero - (Neurogeek)Cloudthunder wrote:> Question: how do I merge two objects? I would like to be able to> have an instance of Foo and an instance of Boo and then be able to > add them together and create a new object that has the methods and> properties of both objects. I am going to be doing a lot of this> and I don't want to have to dynamically (or otherwise) create a > whole bunch of classes that inherit from both Foo and Boo then> create instances of those new children classes. In fact, this> wouldn't work for me anyway because I am going to have an instance> of Foo which will be used within my algorithm for sometime then > later I will want to merge it with a fresh instance of Boo or> otherwise give it all the methods and properties of the Boo class.> Am I making any sense here?>> Thanks.>> - OP >> P.S. I also noticed that we can no long use the __members__> property to get a tuple of all a class's methods. How can I get the> same info from dir()? Dir(), I understand, tells you about all > properties and you can't tell it to just list the methods.-BEGIN PGP SIGNATURE-Version: GnuPG v1.4.1 (GNU/Linux)Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.orgiD8DBQFEMWPzdIssYB9vBoMRAnkLAJ4mkUTlB9POlOyE5MeHukAJ5LeawQCghtoQDsn33bw0LYFsNS2AYStPLdU==Dt4g-END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
