Calling a method from invoking module

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


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.

- b


* *

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

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

* *
class Bar:
    def barz():
        track_this = ...
        if Foo.track(track_this):
        return sth1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list