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

E

ed

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.

Thank you!
 
D

Diez B. Roggisch

ed said:
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
 
L

Lie Ryan

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.

Thank you!

Remember that in python when you do:

A_instance = A()
A_instance.foo(a, b)

is actually the same as

A_instance = A()
A.foo(A_instance, a, b)
 
J

James Mills

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.

I can't help but think there is a better approach to
your problem. Why are you calling in hundreds of places ?
What is it and what does it do ?

cheers
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top