importing a method

Flavio fccoelho at
Mon Nov 28 00:38:18 CET 2005


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

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.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,


More information about the Python-list mailing list