Who Can Tell Me What Can Call The Built-in Functions In Next Code
i know some of this,ex. __mod__ will be call / __eq__will be call == > and < but i don't know all. def __nonzero__(self): # an image is 'true' if it contains at
Solution 1:
Section 3.4 of the Python Language Reference covers the magic methods.
Solution 2:
See the Special Method Names section in the reference manual, including Basic Customization and Emulating Numeric Types.
Solution 3:
__mod__
is called for %
, not for /
as you state:
>>>classx(int):...def__mod__(self, y):...print'__mod__(%s, %s)' % (self, y)...returnint.__mod__(self, y)...>>>a = x(23)>>>a / 4
5
>>>a % 4
__mod__(23, 4)
3
>>>
Make and use similar toy classes to clarify any doubt you may have about a special method, if any are left after you read the docs.
Post a Comment for "Who Can Tell Me What Can Call The Built-in Functions In Next Code"