Where can I find .join() in the docs

Duncan Booth duncan at NOSPAMrcp.co.uk
Fri May 31 09:42:12 EDT 2002


"Russell Blau" <russblau at hotmail.com> wrote in news:ad7sjs$v94d3$1 at ID-
76829.news.dfncis.de:

>> type: float, unicode, open, super, long, complex, dict, type, tuple,
> list,
>> str, property, int, file, object, classmethod, staticmethod
>>
> 
> OK, this intrigues me.  What are <type 'open'> and <type 'super'> ??
> I've never seen any reference to either of these before.

open is an alias for the file type. You can construct a file object by:

   file(name[, mode[, buffering]]) -> file object
is the same as:
   open(name[, mode[, buffering]]) -> file object

>>> print open is file
1

super is used in new style classes to call methods higher in the 
inheritance search order (even if they aren't directly in base classes):

Try this example:

class A(object):
    def save(self):
        print "Save state of A"

class B(A):
    def save(self):
        print "Save state of B"
        super(B, self).save()

class C(A):
    def save(self):
        print "Save state of C"
        super(C, self).save()

class D(B, C):
    def save(self):
        print "Save state of D"
        super(D, self).save()

b1 = B()
print "b1.save()"
b1.save()

d1 = D()
print "d1.save()"
d1.save()

The output of running this is:
b1.save()
Save state of B
Save state of A
d1.save()
Save state of D
Save state of B
Save state of C
Save state of A

Notice that calling the save method on a B object calls the save method in 
its base A object, but calling the B save method when the object is really 
a D the call is instead directed across to the C class.

super is quite clever really. At first sight you might think that 
super(B,d1) would simply return C, but it actually returns a super object 
that delays the base class search until you try to call a method on it. 
This means that if C didn't have a save method the C class could be 
bypassed and super(B,d1).save() would call A.save() instead.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list