importing a method

Flavio fccoelho at gmail.com
Sun Nov 27 18:38:18 EST 2005


hi,

I have an object defined with a number of hardcoded methods.

Class soandso:
    def __init__(self):
        self.this = 0
        self.that = 1
    def meth1(self):
        ...
    def meth2(self):
        ...
    def custom(self):
        pass

I want to allow the user to write a python module that declares a
function so that myprogram can import it and attribute it to the custom
method of the soandso object. So far so good, that is an easy thing to
do in Python.

import usermodule
a=soandso()
a.custom = usermodule.function

But, what if the method had to access the self attributes (self.this
and self.that) of the soandso object?

Can it be done? and if so, what is the most Pythonic way of doing it?

thanks in advance,

Flávio




More information about the Python-list mailing list