[Tutor] Concatenating numeric data in Python 3.3

Dave Angel davea at davea.name
Wed Apr 24 19:29:01 CEST 2013


On 04/24/2013 12:52 PM, sparkle Plenty wrote:
> What is the best way to concatenate packed numeric data?  I am building a
> message to send to a device and it has a very specific header format and
> variable length payload.  Converting to string, concatenating, and then
> converting back to numeric introduced errors.  The tuple() function also
> introduced errors.
>
> The code is proprietary so I am not comfortable posting it.  I have been
> programming in Python for a few weeks.  It is my first OOP language.  My
> background, in the dim and distant past, is mainframe.
>
> Any help would be greatly appreciated.  Thank you in advance.
>
>
>

Some clues would be useful.  For example, what form is your message 
going to be?  Presumably a byte string b"abc", not a real (Unicode) 
string.  There are no limitations on stuffing binary data into a byte 
string.  But not all byte strings make any sense as Unicode, as you have 
to pick a decoder when converting.

On the other hand, you could be just manipulating an array of unsigned 
char, which doesn't even pretend to represent a string.
Create one with
   import data
   data = array.array("B")
-- 
DaveA


More information about the Tutor mailing list