473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with python array's...

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
Jul 18 '05 #1
2 6757
MangoMan wrote:
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

Jul 18 '05 #2
On Fri, 10 Oct 2003 22:45:32 +0000, Alex Martelli wrote:
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

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JW | last post by:
Hi, Below is a description of what I would like to do. Would someone tell me if it is possible and if so, how? I have an array (presumably 'large') that is mallocced in a C function and its...
2
by: Marc Schellens | last post by:
Following the NumPy documentation, I took over some C code, but run into an error. Does anybody have a suggestion? Thanks, marc gdlpython.cpp:225: `PyArray_Type' undeclared (first use this...
1
by: youngdubliner | last post by:
I'm having a problem ........ I've stripped all my code to help isolate the problem. Its seems to be with importing numarray when python is embedded in C. I have a simple C program it Opens...
8
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like the following: PyObject* res =...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
13
by: sonjaa | last post by:
Hi I'm new to programming in python and I hope that this is the problem. I've created a cellular automata program in python with the numpy array extensions. After each cycle/iteration the...
5
by: Yi Xing | last post by:
I tried the following code: ... i=i+1 ... a.append(float(i)) ... Traceback (most recent call last): File "<stdin>", line 3, in ? MemoryError to see the size of the array at the...
1
by: smarras | last post by:
Hello everyone, I keep obtaining an error message whenever I execute some very simple routines; the error that follows says that I am calling certain functions that, in reality, I am not calling...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.