473,545 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Allocated3 2 = offset16
self.Allocated1 6 = offset8-offset16
self.Allocated8 = totalSize-offset8
print "Array should be size %d %d %d (32, 16, 8)" % (self.Allocated 32,
self.Allocated1 6, self.Allocated8 )

self.buffer32.f romfile(self.fs ,self.Allocated 32)
self.buffer16.f romfile(self.fs ,self.Allocated 16)
self.buffer8.fr omfile(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 6766
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.Allocated3 2 = offset16
self.Allocated1 6 = offset8-offset16
self.Allocated8 = totalSize-offset8
print "Array should be size %d %d %d (32, 16, 8)" % (self.Allocated 32,
self.Allocated1 6, 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
4229
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 values are initialized in that same function. I would like to pass just the pointer to the beginning of the array
2
2940
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 function) #include <python2.3/Python.h>
1
1972
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 Python imports a script and then Closes Python like so .......
8
3843
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 = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE, char*buf); Users will get a Numeric Array object and can change its values (and actually change the...
8
3016
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 what I really should do. I've had a look through Programming Python and the Python Cookbook, which have given me ideas, but nothing has gelled...
2
4432
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 */ #include <time.h>
13
2948
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 memory used to examine and change the array as determined by the transition rules is never freed. I've tried using "del" on every variable possible, but...
5
363
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 time of memory error:
1
27816
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 from any of the routines that I wrote: error: 0, 0, 0, 0 , 0, 1, 2, 3 , 0, 2, 4, 6 Traceback (most recent call last):
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.