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

Discussion in 'Python' started by ed, Oct 22, 2008.

  1. ed

    ed Guest

    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!
     
    ed, Oct 22, 2008
    #1
    1. Advertising

  2. 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
     
    Diez B. Roggisch, Oct 22, 2008
    #2
    1. Advertising

  3. ed

    Lie Ryan Guest

    On Wed, 22 Oct 2008 12:34:26 -0400, 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.
    >
    > 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)
     
    Lie Ryan, Oct 26, 2008
    #3
  4. ed

    James Mills Guest

    On Thu, Oct 23, 2008 at 2:34 AM, 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.


    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

    --
    --
    -- "Problems are solved by method"
     
    James Mills, Oct 26, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. baumann@pan
    Replies:
    8
    Views:
    763
    Achintya
    May 10, 2005
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    935
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,128
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    3
    Views:
    955
    Roedy Green
    Jan 28, 2008
  5. Jase Schick
    Replies:
    11
    Views:
    602
    Geoff
    Aug 5, 2010
Loading...

Share This Page