method-wrapper?

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

    method-wrapper?

    Hi,

    Within Python (2.5):
    >>help("__str__ ")
    Help on method-wrapper object:
    __str__ = class method-wrapper(object)
    | Methods defined here:
    |
    | __call__(...)
    | x.__call__(...) <==x(...)
    |
    | __cmp__(...)
    | x.__cmp__(y) <==cmp(x,y)
    [...]

    What is "method-wrapper"? Google turns up hardly any hits, same with
    searching python.org.

    Thanks,
    Andrew
  • David

    #2
    Re: method-wrapper?

    What is "method-wrapper"? Google turns up hardly any hits, same with
    searching python.org.
    >
    It probably means that one object (A) contains another object (B).
    When you call certain methods on object A, those methods call methods
    in B, and return B's results to A's caller.
    >From that docstring:
    A.__call__() will run B()
    A.__cmp__(C) will run cmp(B, C)

    etc.

    In other words python code which runs A() will be running the
    equivalent of A.B(), where A can do other things besides calling B()
    if it wants to.

    David.

    Comment

    • Gabriel Genellina

      #3
      Re: method-wrapper?

      En Sat, 31 May 2008 13:46:45 -0300, andrew cooke <andrew@acooke. org>
      escribió:
      Hi,
      >
      Within Python (2.5):
      >
      >>help("__str__ ")
      Help on method-wrapper object:
      __str__ = class method-wrapper(object)
      | Methods defined here:
      |
      | __call__(...)
      | x.__call__(...) <==x(...)
      |
      | __cmp__(...)
      | x.__cmp__(y) <==cmp(x,y)
      [...]
      >
      What is "method-wrapper"? Google turns up hardly any hits, same with
      searching python.org.
      After looking at the code in descrobject.c, I *think* a method-wrapper is
      used to create a Python object out of internal methods (stored as C
      function pointers in the type structure), as if they were actual Python
      methods.
      That is, they wrap an internal function pointer (defined in the type)
      along with a Python object ("self"), so it can be used in Python code as
      it were a normal instance method. But certainly I can be wrong...

      --
      Gabriel Genellina

      Comment

      Working...