Bug or wart? You make the call.

Steven Taschuk staschuk at telusplanet.net
Sun Mar 9 14:06:26 EST 2003


Quoth Jeremy Fincher:
  [...]
> But why does it need to be done at all?  If methods are really just
> functions whose first argument is an instance, why does a method
> object need to be created?

So you don't have to specify the first argument explicitly every
time you call the method.

Consider:
	import glob
	spam = []
	glob.glob('tiger*')
	spam.append('tiger*')
The interpreter treats these two calls in the same way: look up
the object foo.bar and call it with single argument 'tiger*'.

glob.glob is a normal function, whose only arguments are those
explicitly provided, while spam.append is a bound method with an
implicit self argument.  The interpreter doesn't care; the
difference is achieved by polymorphism of the callables.  It's
almost as if spam.append were the object
	lambda x: list.append(spam, x)
(It isn't, of course; it's a bound method object.  But whatever it
is, it's the thing that takes care of the specialized currying in
this case.)

-- 
Steven Taschuk                                                   w_w
staschuk at telusplanet.net                                      ,-= U
                                                               1 1





More information about the Python-list mailing list