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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ed

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

    I'm trying to make a shortcut by doing this:

    t = Globals.ThisCla ss.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!
  • Diez B. Roggisch

    #2
    Re: Why can't I assign a class method to a variable?

    ed wrote:
    I'm trying to make a shortcut by doing this:
    >
    t = Globals.ThisCla ss.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

    Comment

    • Lie Ryan

      #3
      Re: Why can't I assign a class method to a variable?

      On Wed, 22 Oct 2008 12:34:26 -0400, ed wrote:
      I'm trying to make a shortcut by doing this:
      >
      t = Globals.ThisCla ss.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_instanc e, a, b)

      Comment

      • James Mills

        #4
        Re: Why can't I assign a class method to a variable?

        On Thu, Oct 23, 2008 at 2:34 AM, ed <ed@nospam.netw rote:
        I'm trying to make a shortcut by doing this:
        >
        t = Globals.ThisCla ss.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"

        Comment

        Working...