A TYPICAL NEWBIE MISTAKE?
Courageous
jkraska1 at san.rr.com
Sun May 14 21:19:20 EDT 2000
Over the last few weeks, I've taken to creating
classes thusly:
class MyClass
i=0
f=3.1
s="str"
ll=[]
def __init__(...)...
This has been an interesting experiment. While I
was aware that class variables in Python were "static"
until assigned, it took me until today to learn a bit
of a stinger of a lesson. To wit: append()ing to
a list or assigning to a dictionary does not count
as "assigned".
I spent quite a while this afternoon figuring this
out. This must be a fairly common error. The solution
is obvious. If you want to assign class variables as
commentary the way I do, make sure you assign everyone
in the __init__() method, ala:
class MyClass
i=0
f=3.1
s="str"
ll=[]
def __init__()
i=0
f=3.1
s="str"
ll=[]
Albeit, now that I understand everything, this seems a
bit reduntant. :)-
C/
More information about the Python-list
mailing list