defining class functions

Astan Chee astan.chee at al.com.au
Mon Jan 19 19:36:03 EST 2009


Actually, yes, I just realized a better way of doing this without state 
change based on the requirement.
Thanks for the info anyway

Nehemiah Dacres wrote:
> wouldn't you use a state change? Use a variable to indicate which 
> function you want the first class to do
>
> On Mon, Jan 19, 2009 at 6:31 PM, James Mills 
> <prologic at shortcircuit.net.au <mailto:prologic at shortcircuit.net.au>> 
> wrote:
>
>     On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee <astan.chee at al.com.au
>     <mailto:astan.chee at al.com.au>> wrote:
>     > Hi,
>     > I have two classes in python that are in two different
>     files/python scripts.
>     > Class A uses Class B like this:
>     > class B(object):
>     >   def function1(self,something):
>     >       pass
>     >   def function2(self,something):
>     >       print "hello one"
>     >       print something
>     >
>     > class A(object):
>     >   def __init__(self):
>     >         instance = B()
>     >         instance.function2("hello two")
>     >         self.function3()
>     >   def function3(self):
>     >         print "hello three"
>
>     def function3(self):
>       print "hello three"
>       self.instance.function1 = lambda x; x
>
>     But you must bind instnace to self in B
>
>     Modify your __init__ as follows:
>
>     class A(object):
>       def __init__(self):
>          self.instance = B()
>          self.instance.function2("hello two")
>          self.function3()
>
>     What's the use-case anyway ?
>     There might be a better way to solve your problem :)
>
>     cheers
>     James
>     --
>     http://mail.python.org/mailman/listinfo/python-list
>
>
>
>
> -- 
>
> "lalalalala! it's not broken because I can use it"
>
> http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703 
> <http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090120/8e1907f3/attachment-0001.html>


More information about the Python-list mailing list