468,468 Members | 2,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,468 developers. It's quick & easy.

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 3303
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Gordon Scott | last post: by
reply views Thread by Josiah Carlson | last post: by
2 posts views Thread by Sergey Dorofeev | last post: by
3 posts views Thread by Chandu | last post: by
10 posts views Thread by Giovanni Bajo | last post: by
3 posts views Thread by David Bear | last post: by
2 posts views Thread by Tom Plunket | last post: by
2 posts views Thread by Jansson Christer | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.