PEP 285: Adding a bool type

Alex Martelli aleax at aleax.it
Wed Apr 3 01:27:58 EST 2002


David Eppstein wrote:
        ...
> I can't think of a language change that has made me very unhappy, but

I can only think of one (print>>bah)...

> There's plenty of change I'm neutral or ignorant of, like most of the
> object-oriented infrastructure stuff.  What is staticmethod etc anyway?

class Peep:
    def anyfunc(): print "note, no 'self'"
    anyfunc = staticmethod(anyfunc)

p = Peep()

p.anyfunc()
Peep.anyfunc()

prints "note, no 'self'" twice.  Just a peculiar way of packaging functions
so they can be attributes of a class without thereby becoming unbound
methods when accessed.  classmethod is more powerful, but according
to the tutorial the inability to upcall naturally from it means Guido knows
of no use cases for it and is thinking about taking it away again (maybe
some Smalltalkers will put together an impressive array of practical
use cases... let's hope...!).  It works similarly:

class Qeep:
    def anyfunc(cls): print "called on class", cls.__name__
    anyfunc = classmethod(anyfunc)

class Reep(Qeep): pass

q = Qeep()
r = Reep()

q.anyfunc()
Qeep.anyfunc()
r.anyfunc()
Reep.anyfunc()

prints "called on class Qeep" twice, then "called in class Reep" twice.


> So that seems like a very good ratio to me.

A great ratio, yes.


Alex




More information about the Python-list mailing list