Why can't I assign a class method to a variable?

Diez B. Roggisch deets at nospam.web.de
Wed Oct 22 12:45:05 EDT 2008


ed wrote:

> I'm trying to make a shortcut by doing this:
> 
> t = Globals.ThisClass.ThisMethod
> 
> Calling t results in an unbound method error.
> 
> Is it possible to do what I want?  I call this method in hundreds of
> locations and I'm trying to cut down on the visual clutter.

You need to make the method a staticmethod or classmethod. Or pass an
ThisClass-instance as first argument.

Diez



More information about the Python-list mailing list