Python 3K or Python 2.9?
bignose+hates-spam at benfinney.id.au
Thu Sep 13 04:20:41 CEST 2007
TheFlyingDutchman <zzbbaadd at aol.com> writes:
> I would mention that an instance is passed as the first parameter
> argument of a method if the methods were declared with the extra
> argument and called with the extra argument:
> a = MyClass()
Are you unaware that this is the way it works already?
>>> class Foo(object):
... def bar(self, baz):
... print baz
>>> foo = Foo()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unbound method bar() must be called with Foo instance as first argument (got str instance instead)
>>> Foo.bar(foo, "spam")
The latter two statements are equivalent. The 'instance.method(args)'
syntax is just sugar for 'Class.method(instance, args)'.
\ "Choose mnemonic identifiers. If you can't remember what |
`\ mnemonic means, you've got a problem." -- Larry Wall |
More information about the Python-list