By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,538 Members | 1,428 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,538 IT Pros & Developers. It's quick & easy.

struct.pack Format String Question

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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.