Calling a method from invoking module

Baskaran Sankaran baskarans at gmail.com
Fri Oct 29 01:59:07 CEST 2010


Hi,

I have two classes in separate python modules and I need to access some
methods of the either classes from the other. They are not in base and
derived class relationship.

Please see the example below. Foo imports Bar and inside the Foo class it
creates a Bar obj and then calls Bar.barz(). Now before returning control,
it has to call the track method in Foo.

As I understand, I won't be able to use 'super' in this case, as there is no
inheritance here. Also, I won't be able to move the track method to Bar as I
need to track different bar types.

Any suggestion on how to get this done would be great. Thanks in advance.

Cheers
- b

----------

* foo.py *

import bar
class Foo:
    def fooz():
        print "Hello World"
        b = Bar()
        c = b.barz()
        ...

    def track(track_var):
        count += 1
        return sth2


* bar.py *
class Bar:
    def barz():
        track_this = ...
        if Foo.track(track_this):
            pass
        else:
            ...
        return sth1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101028/44779191/attachment.html>


More information about the Python-list mailing list