Problem with python array's...

M

MangoMan

Hi there,

Currently i am having a problem with python's array class.

I am reading 3 arrays from a file (self.buffer32, self.buffer16,
self.buffer8 from self.fs) :

# ...
self.Allocated32 = offset16
self.Allocated16 = offset8-offset16
self.Allocated8 = totalSize-offset8
print "Array should be size %d %d %d (32, 16, 8)" % (self.Allocated32,
self.Allocated16, self.Allocated8)

self.buffer32.fromfile(self.fs,self.Allocated32)
self.buffer16.fromfile(self.fs,self.Allocated16)
self.buffer8.fromfile(self.fs,self.Allocated8)
# ...

According to my code, each array should be 6 items long. However, when
printing out the buffer's after reading, i get :

Array should be size 6 6 6 (32, 16, 8)
Buffers :
array('b', [72, 73, 0, 72, 73, 0, 1, 2, 3])
array('h', [0, 1, 657, 0, 1, 657, 666, 2, 3])
array('i', [0, 2000, 1000, 0, 2000, 1000, 1, 2, 3])

And if you wish to know, the buffer's should be :

array('b', [72, 73, 0, 1, 2, 3])
array('h', [0, 1, 657, 666, 2, 3])
array('i', [0, 2000, 1000, 1, 2, 3])

(b is buffer8, h is buffer16, i is buffer32)
Mysteriously, 3 extra items are added onto each array, in exactly the same
place. When looking at the file in a hex editor, these number's do not
exist at all!

Can anyone suggest what on earth is going on?

Version output of python -v :
Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
(Simply Redhat 9 with the Python 2.2.2)


Thanks for any help
-MangoMan
 
A

Alex Martelli

MangoMan said:
Hi there,

Currently i am having a problem with python's array class.

I am reading 3 arrays from a file (self.buffer32, self.buffer16,
self.buffer8 from self.fs) :

# ...
self.Allocated32 = offset16
self.Allocated16 = offset8-offset16
self.Allocated8 = totalSize-offset8
print "Array should be size %d %d %d (32, 16, 8)" % (self.Allocated32,
self.Allocated16, self.Allocated8)

Hmmm -- are the len(...) of the three arrays zero at this point?
The fromfile method appends what it reads to what was already
in the array, rather than overwriting it -- and I don't see your code
emptying out these arrays nor checking them for 0 length...

Alex
 
M

MangoMan

Hmmm -- are the len(...) of the three arrays zero at this point?
The fromfile method appends what it reads to what was already
in the array, rather than overwriting it -- and I don't see your code
emptying out these arrays nor checking them for 0 length...

Alex

Alex,
It turns out i was not cleaning up the buffer's properly when i deleted
the instance of my object (thus causing any new instances to screw up the
buffer)

Thanks =)
-MangoMan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,448
Latest member
DeanaQ4445

Latest Threads

Top