473,394 Members | 1,717 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,394 software developers and data experts.

struct.pack Format String Question

Hello. I am reverse engineering some Python Code. I am using the book
"The Quick Python Book" as an aide.

The following line exists in the code:

msg = struct.pack('BBBB',word0, word1, word2, word3, word4)

In this struct.pack command, the format string is 'BBBB.' In the book,
it gives the following examples for characters that are meaningful to
struct:

'h' - short integer
'd' - double-precision floating point
's' - string

In this case, 'B' is used. What does 'B' represent? What other
characters can be used? Does a list of this exist somewhere?

Thank you for your help.

Josh

Jul 18 '05 #1
2 3628
Joshua Forgione wrote:
In this case, 'B' is used. What does 'B' represent? What other
characters can be used? Does a list of this exist somewhere?


http://www.python.org/doc/current/li...le-struct.html

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ But you're not going to be there tomorrow. And it's all about
tomorrow. -- Montgomery Brogan
Jul 18 '05 #2
"B" is unsigned character (from Python Library Reference).

I'm hoping you copied the line down wrong, because it won't
work (there is probably another B).

See output below:

import struct
word0=1
word1=2
word2=3
word3=4
word4=5
msg = struct.pack('BBBB',word0, word1, word2, word3, word4)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
error: too many arguments for pack format

Larry Bates
Syscon, Inc.

-------------------------------------------------------

"Joshua Forgione" <jf******@vt.edu> wrote in message
news:40***************@vt.edu...
Hello. I am reverse engineering some Python Code. I am using the book
"The Quick Python Book" as an aide.

The following line exists in the code:

msg = struct.pack('BBBB',word0, word1, word2, word3, word4)

In this struct.pack command, the format string is 'BBBB.' In the book,
it gives the following examples for characters that are meaningful to
struct:

'h' - short integer
'd' - double-precision floating point
's' - string

In this case, 'B' is used. What does 'B' represent? What other
characters can be used? Does a list of this exist somewhere?

Thank you for your help.

Josh

Jul 18 '05 #3

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

Similar topics

3
by: Gordon Scott | last post by:
Hi All, I've got a problem I'm seeing when trying to use the struct module to send data to a different machine. Actually I'm making a condensed file that gets transferred to and read on a BREW...
0
by: Josiah Carlson | last post by:
Good day everyone, I have produced a patch against the latest CVS to add support for two new formatting characters in the struct module. It is currently an RFE, which I include a link to at the...
2
by: Sergey Dorofeev | last post by:
I can use string.unpack if string in struct uses fixed amount of bytes. But is there some extension to struct modue, which allows to unpack zero-terminated string, size of which is unknown? E.g....
16
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
3
by: Chandu | last post by:
In using the following struct format I get the size as 593. The same C struct is 590 if packed on byte boundary and 596 when using pragma pack(4). I am using pack(4) and added 3 spares at the end...
10
by: Giovanni Bajo | last post by:
Hello, given the ongoing work on struct (which I thought was a dead module), I was wondering if it would be possible to add an API to register custom parsing codes for struct. Whenever I use it...
3
by: David Bear | last post by:
I found this simple recipe for converting a dotted quad ip address to a string of a long int. struct.unpack('L',socket.inet_aton(ip)) trouble is when I use this, I get struct.error: unpack...
2
by: Tom Plunket | last post by:
I am building a file with the help of the struct module. I would like to be able to put Unicode strings into this file, but I'm not sure how to do it. The format I'm trying to write is...
2
by: Jansson Christer | last post by:
Hi all, I have discovered that in my Python 2.4.1 installation (on Solaris 8), struct.pack handles things in a way that seems inconsistent to me. I haven't found any comprehensible...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.