Add methods to a class at runtime?

Stefan Schwarzer sschwarzer at
Sun Sep 1 17:32:13 EDT 2002

Hello Robert

Robert Oschler wrote:
> Thanks but I need a little bit more detail.  Suppose I want to do it from
> within code?  For example, I create a function called
> AddBarToFoo(FooObject), that given a object of type Foo (FooObject) adds the
> Bar method to it dynamically, what would be the syntax then?  Would I have
> to put the method declaration code, which you show being typed in to the
> interpreter, in a string and then eval/exec it?  Is there a more convenient
> way than that?

There was a thread on this some time ago:

Maybe that is helpful. :)


More information about the Python-list mailing list