In <[EMAIL PROTECTED]>, madpython
wrote:

> I've been doing an application with Tkinter widgets. Nothing really
> fancy just routine stuff. Though I have no problems with it by now I
> guess it would be reasonable to ask about a thing that's been bothering
> me a bit. Look at this piece of code:
> 
> class A(object):
>     def a(self):
>         return "a from A"
> 
> class B(object):
>     def interClassCall(self):
>         print globals()['c'].__dict__['a'].a()
> 
> class C(object):
>     def __init__(self):
>         self.a=A()
>         self.b=B()
>     def c(self):
>         self.b.interClassCall()
> 
> if __name__=="__main__":
>     c=C()
>     c.c()
> 
> What is another way to get data from method of another instance of a
> class? Or maybe print globals()['c'].__dict__['a'].a() is perfectly
> normal. I need your professional expertise.

No it's not the normal way.  Why don't you give `c` as argument to the
`interClassCall()`?

class B(object):
    def interClassCall(self, c):
        print c.a.a()

class C(object):
    def __init__(self):
        self.a=A()
        self.b=B()
    def c(self):
        self.b.interClassCall(self)

Much less magic involved this way.

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to