always the same object (2)

Uwe Mayer merkosh at
Wed Jan 21 01:14:51 CET 2004


sorry for the lack of source code. 
Here again:

I use struct.unpack() to unpack data from a binary file and pass the
returned tuple as parameter to __init__ of a class that's supposed to
handle the data:

class DataWrapper():
        data = { }
        def __init__(self, arg): #arg will contain a tuple
                data['var1'], data['var2'] = arg

result = [ ]
while not <end-of-file f>:
        data = struc.unpack("4s4s", 
        record = DataWrapper( data ) # pass tuple from unpack 
        result.append( record )

Then "result" contains a list with different objects, but the strings 
in data['var1'] and data['var2'] are all the same.

Any ideas how to avoid this?

Thanks again

More information about the Python-list mailing list