defining class functions

Nehemiah Dacres vivacarlie at gmail.com
Mon Jan 19 19:33:27 EST 2009


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>wrote:

> On Tue, Jan 20, 2009 at 10:08 AM, Astan Chee <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090119/20c5bf8b/attachment-0001.html>


More information about the Python-list mailing list