Hello Matimus,
On 2006-09-07 00:07, Matimus wrote:
> Someone correct me if I'm wrong (sometimes I get the terms mixed up)
> but I believe that what you are seeing is due to 'number' being an
> immutable type. This means that its value cannot be changed and thus
> each assignment is effectively cre
Someone correct me if I'm wrong (sometimes I get the terms mixed up)
but I believe that what you are seeing is due to 'number' being an
immutable type. This means that its value cannot be changed and thus
each assignment is effectively creating a new instance if int. I
believe lists are considered
Greetings again!
There's something more to determining whether a class member is a class
variable or an instance variable. Here's a slightly expanded version
of my last script:
class ScannerCommand:
taskName = ''
scanList = []
number = 0
def __init__(self, data):
pass
#
[EMAIL PROTECTED] wrote:
> Skip and Matimus,
>
> Thank you for your replies. Putting initialization in the constructor
> gets me what I want. But I'd like to understand this a bit more.
> Here's another script:
>
> class ScannerCommand:
> taskName = ''
> scanList = []
>
> def __ini
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 = []
C
Skip and Matimus,
Thank you for your replies. Putting initialization in the constructor
gets me what I want. But I'd like to understand this a bit more.
Here's another script:
class ScannerCommand:
taskName = ''
scanList = []
def __init__(self, data):
self.scanList = []
taskName and scanList are defined at the class level making them class
attributes. Each instance of the ScannerCommand class will share its
class attributes. What you want are instance attributes which can be
initialized whithin the constructor like so:
>>> class ScannerCommand:
... def __init
Cedric> Why is the ScannerCommand object being created with a scanList
Cedric> that contains the data that was in the previously created
Cedric> ScannerCommand object?
Your scanList attribute is defined at the class level and is thus shared by
all ScannerCommand instances.
Skip
--
h