On Sat, 26 Feb 2000 london999 at my-deja.com wrote:
I am very new to Python, but it appears that every function defined in a
class must have self as a first variable name.
No, it can call the argument what it likes. "self" is the most popular,
by far. "me", "my" and "s" are poor contestants most people don't even
know about. But it's a convention, not a rule.
Assuming that is the
case, it would be nice if there was an error message given when the
interpreter encounters a function that is defined without self (rather
than giving the error message "TypeError: no arguments expected" when
the function is called.
It can't. Consider:
foo.bar = bar
a = foo()
The only time the interpreter can give the error is when a.bar() is
called, and that's when it does.
Even better, it would be nice (probably too late
I know), if self was defined implicitly as the "this" pointer is in C++.
That would add another keyword to the language, and contradict one of
Python's principles "explicit is better then implicit"
Moshe Zadka <mzadka at geocities.com>.
INTERNET: Learn what you know.
Share what you don't.