472,780 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 1230
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.