Method binding confusion

Josiah Carlson jcarlson at uci.edu
Mon May 24 20:21:07 EDT 2004


> This problem, and a lot of others that confuse beginners could be
> eliminated if all functions and methods had exactly the same sequence
> of arguments (no special first argument).

It can be done.

 >>> import math
 >>>
 >>> def mypow(x, y):
...       return x**y
...
 >>> class MathA:
...    pow = math.pow
...
 >>> class MathB:
...    pow = staticmethod(mypow)
...
 >>> ma = MathA()
 >>> mb = MathB()
 >>>
 >>> ma.pow(2,4)
16.0
 >>> mb.pow(2,4)
16

Whether or not there should be an implied self or not, is a value 
judgement.  Guido (and everyone else who works on the core Python 
language) has heard your (and everyone else's) arguments before.  I 
would put good odds on there not likely to be /any/ sort of change 
toward what you are advocating (the merging of functions and methods) in 
the forseeable future (before Python 3.0) in standard Python.  And even 
in the far future (Python 3.0), there is no guarantee.

  - Josiah



More information about the Python-list mailing list