BartC <b...@freeuk.com>: >>> On 08/11/2015 11:50, Marko Rauhamaa wrote: >>>> ======================================================================== >>>> import shutil >>>> >>>> class Source: >>>> def __init__(self): >>>> self.remaining = "hello world" >>>> >>>> def read(self, count): >>>> if count <= 0: >>>> return "" >>>> chunk, self.remaining = self.remaining[:count], >>>> self.remaining[count:] >>>> return chunk >>>> >>>> class Dest: >>>> def write(self, stuff): >>>> print("<{}>".format(stuff)) >>>> >>>> shutil.copyfileobj(Source(), Dest()) >>>> ======================================================================== > > What exactly is being looked up, and in what? > > [...] > > So to get back to what I was saying, does this lookup involving > searching for method B in object A, and if so, does it actually do a > search by name?
Yes, finding Source.read and Dest.write involves hash table lookups. In fact, it's even a bit more involved: each method fetch consists of *two* hash table lookups. First you have to check if the object has a match in its individual lookup table and next if there is a match in the class's lookup table. Marko -- https://mail.python.org/mailman/listinfo/python-list