A TYPICAL NEWBIE MISTAKE?
Courageous
jkraska1 at san.rr.com
Sun May 14 22:57:37 EDT 2000
> > def __init__()
> >
> > i=0
> > f=3.1
> > s="str"
> > ll=[]
>
> Actually, it should be:
>
> class MyClass:
>
> def __init__():
> self.i = 0
> self.f = 3.1
> self.s = "str"
> self.ll = []
You forgot the (self) in the def line... :)
> Note that without the 'self.' in __init__() (or any other method), a
> variable *local to that method* is created; the variables would disappear
> upon the completion of the method.
Yeah, I make that mistake all the time. The interpreter
is constantly correcting me. It's my c++/java background
with its implicit "this".
I miss the colons all the time, too (as Mr. Pinard so
readily pointed out.... ha). Which brings me to the topic.
Sometimes colons seem syntactically unnecessary. For example:
if <condition>:
statement
else:
statement
Really, else doesn't need a colon, as far as I can tell
(I can see the need for the if, supposing you wan to
have the statement on the same line).
Doesn't seem like "def" does, either.
C/
More information about the Python-list
mailing list