unbound method
Verfasst: Samstag 30. Oktober 2004, 23:05
[vielleicht nur eine blöde frage von einem anfänger]
ich habe wohl nicht verstanden, was "unbound methods" sind.ich kriege einfach think_unbound() nicht aufgerufen.
wie geht das?
ich habe wohl nicht verstanden, was "unbound methods" sind.
Code: Alles auswählen
class Foo:
def __init__(self, name):
self.name = name
def think_unbound():
print "I'm %s and I'm unbound :D yeah it's freedom man" % self.name
def think(self):
print "I'm %s and I'm bound :( *sniff*" % self.name
herby = Foo('Herby')
herby.think() #-> I'm bound :( *sniff*
Foo.think_unbound() #-> TypeError: unbound method think_unbound() must be called with Foo instance as first argument (got nothing instead)
Foo.think_unbound(herby) #-> TypeError: think_unbound() takes no arguments (1 given)
wie geht das?