Home

TheFlyingDutchman <zzbbaadd@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()
>
> my_method(a,someParameter)

Are you unaware that this is the way it works already?

>>> class Foo(object):
... def bar(self, baz):
... print baz
...
>>> foo = Foo()
>>> Foo.bar("spam")
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")
spam
>>> foo.bar("spam")
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 |
_o__) |
Ben Finney

previous
next

Re: STL vector iterator question
Re: Howto design my method?
Re: C++ Primer ex 6.20
Re: Newby C++ vs. C question
Re: string array ...
Mam Marzenie
Dzieci Niczyje
Fundacja Avalon
Niechciane i Zapomniane
Fundacja Iskierka