Data sticking around too long
skip at pobox.com
skip at pobox.com
Wed Sep 6 16:58:22 EDT 2006
Cedric> But I'd like to understand this a bit more.
Always a good idea. ;-)
Cedric> Here's another script:
Cedric> class ScannerCommand:
Cedric> taskName = ''
Cedric> scanList = []
Cedric> def __init__(self, data):
Cedric> self.scanList = []
Cedric> self.scanList.append(data)
...
The assignment to self.scanList in __init__ creates an instance attribute in
the ScannerCommand instance. The scanList attribute at the class level is
available as ScannerCommand.scanList. In your previous code, (no assignment
to self.scanList in __init__), references to self.scanList would search
first in the instance dict for a "scanList" key, then failing to find
anything there, search the class's dict and find its "scanList" key.
Skip
More information about the Python-list
mailing list