473,320 Members | 2,145 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,320 software developers and data experts.

using builtin array

Is it possible to join/append 2 arrays defined with different
typecodes?

What typecode should i use to generate the following output.

data1 = array('h', '\0', 6)
data2 = array('L', '\0', 25)

for i in range( 6):
data1[0] = 0xFF
data2[1] = 0x00
data1[2] = 0x00
data1[3] = 0x00
data1[4] = 0x00
data1[5] = 0x00

for i in range( 2):
data2[0] = 0xF0F0F0F0
data2[1] = 0xFFFFFFFF

Output should be...
(0xFF 0x00 0x00 0x00 0x00 0x00 0xF0F0F0F0 0xFFFFFFFF)

Thank You,
-SB

Jul 19 '05 #1
4 1241
sh********@gmail.com wrote:
Is it possible to join/append 2 arrays defined with different
typecodes?

What typecode should i use to generate the following output.

data1 = array('h', '\0', 6)
data2 = array('L', '\0', 25)

for i in range( 6):
data1[0] = 0xFF
data2[1] = 0x00
data1[2] = 0x00
data1[3] = 0x00
data1[4] = 0x00
data1[5] = 0x00

for i in range( 2):
data2[0] = 0xF0F0F0F0
data2[1] = 0xFFFFFFFF

Output should be...
(0xFF 0x00 0x00 0x00 0x00 0x00 0xF0F0F0F0 0xFFFFFFFF)

An arry has one typecode that applies to all its elements - so what you
want can't be done.

But you can use two lists and the module struct to create a string that
resembles the memory layout you want.
data1 = [0] * 6
data2 = [0L] * 25

struct.pack("b" * len(data1) + "l" * len(25), *(data1 + data2))

But I think you should give us more information on what you actually
want to accomplish, as I've got the impression that you try to force
things in awy that is not optimal.

Diez
Jul 19 '05 #2
I am constructing a packet, with the first 6 bytes being the
destination address, followed by src, and type. The remaining space
will be filled with data. I need to use an array because of the
buffer_info method i am calling.

-SB

Jul 19 '05 #3
as*****@gmail.com wrote:
I am constructing a packet, with the first 6 bytes being the
destination address, followed by src, and type.
As I told you - use struct.
The remaining space
will be filled with data. I need to use an array because of the
buffer_info method i am calling.


That's a circular argument - to use arrays because of a methods arrays
habe. Use lists instead. And if you really need that buffer_info, you
could create a string with struct and then make an array of bytes out of
that.

Arrays are homogenous. No chance concatenating them.
Diez
Jul 19 '05 #4
Arrays are homogenous. No chance concatenating them.


This should of course read "No chance concatenating arrays of different
typecodes".
--
Regards,

Diez B. Roggisch
Jul 19 '05 #5

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

Similar topics

0
by: Joachim Dahl | last post by:
I would like to inherit the builtin array class and write som extension methods in C. Other people have suggested that I use numarray for that, but all I want is a simple continuous C array of...
2
by: BJörn Lindqvist | last post by:
A problem I have occured recently is that I want to subclass builtin types. Especially subclassing list is very troublesome to me. But I can't find the right syntax to use. Take for example this...
5
by: bandw | last post by:
I am having a problem using Numeric-24.0b2 in conjunction with the NetCDF module from ScientificPython (version 2.4.9). This problem does not surface using Numeric-23.8. The problem arises in...
7
by: Rich | last post by:
Is there any builtin functionality to the SqlDataReader for getting a row count of records retrieved? Rather than Do While rdr.Read: i+=1: Loop?
6
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
3
by: amitsoni.1984 | last post by:
Hi, I have to write a code in python to read a matrix from a text file and for that i am using following code. But it gives an error saying "NameError: name 'split' is not defined". Can anyone...
20
by: Ari Krupnik | last post by:
scripts can add methods to the prototypes of builtin objects in JaavScript. I can assign functions to String.prototype.*, for instance. I want to add a method to Node, but when I try to execute...
1
by: iwl | last post by:
Hello, there is an builtin documented array module in phyton, but no documentation how such an array can be created in C-Extension functions. So I have to use Lists at time, but this is I think...
1
by: DK | last post by:
I have an intranet application I've built using asp.net 3.5 / running on IIS6 I want to use BUILTIN groups on the server that contain domain users. So I set up my web.config like so for example:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.