Message91864
From:
http://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy
"Class instances
Class instances are described below. Class instances are callable
only when the class has a __call__() method; x(arguments) is a shorthand
for x.__call__(arguments)."
The following program demonstrates otherwise regarding that last statement.
def call(self):
print "inserted __call__ in object of class A"
class A(object):
def __call__(self):
print "__call__ method in class A"
x = A() # Equates: x = type(A).__call__(A)
x.__call__ = call
x() # Calls the method of class A.
x.__call__(x) # Calls function "call".
type(x).__call__(x) # The correct longhand of x() IMHO
If I were to rephrase the documentation:
"Class instances
Class instances are described below. Class instances are callable
only when the class has a __call__() method; x(arguments) is a shorthand
for type(x).__call__(x, arguments)." |
|
Date |
User |
Action |
Args |
2009-08-22 17:13:59 | onlyme | set | recipients:
+ onlyme, georg.brandl |
2009-08-22 17:13:59 | onlyme | set | messageid: <1250961239.16.0.126736964049.issue6761@psf.upfronthosting.co.za> |
2009-08-22 17:13:57 | onlyme | link | issue6761 messages |
2009-08-22 17:13:56 | onlyme | create | |
|