By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

method-wrapper?

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Jun 27 '08 #2

P: n/a
En Sat, 31 May 2008 13:46:45 -0300, andrew cooke <an****@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

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.