Adding new methods at runtime to a class

Roy Smith roy at
Mon Nov 24 22:22:38 CET 2003

In article <mailman.1036.1069707396.702.python-list at>,
 "Delaney, Timothy C (Timothy)" <tdelaney at> wrote:

> > From: Fernando Rodriguez
> > 
> > How can I add new methods at runtime to a class?
> Before we send you into what most would consider black magic in Python, you 
> should explain why you want to.
> In most cases, this is *not* what you want to do - there are better, more 
> elegant and much more Pythonic ways of doing it.
> Tim Delaney

Why is it unpythonic to add methods at runtime?  That's the nature of a 
dynamic language.  If doesn't have to exist until the moment 
it's evaluated, why should have to?  Or maybe a better way to 
ask it is why should have to be callable at any other time than 
when you evaluate

I would say that the fact that all of a class's methods have to be 
declared at once is itself somewhat unpythonic.

More information about the Python-list mailing list