Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > using builtin array

Reply
Thread Tools

using builtin array

 
 
shama.bell@gmail.com
Guest
Posts: n/a
 
      06-01-2005
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

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      06-01-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
ashtonn@gmail.com
Guest
Posts: n/a
 
      06-01-2005
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

 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      06-01-2005
(E-Mail Removed) 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
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      06-02-2005

> Arrays are homogenous. No chance concatenating them.


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

Diez B. Roggisch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
subtle error slows code by 10x (builtin sum()) - replace builtin sumwithout using import? bdb112 Python 2 07-02-2011 03:13 AM
builtin array union intersection function Peng Yu Perl Misc 1 12-31-2009 04:19 PM
ASP.Net Book without builtin control use? mjpmsa@yahoo.com ASP .Net 6 06-11-2005 10:24 PM
Using group authentication with builtin Windows client srp336@getcoactive.com Cisco 1 01-23-2005 05:57 PM
extending the builtin array class from C Joachim Dahl Python 0 08-14-2004 09:32 PM



Advertisments