text strings to binary...

O

oriana.falco

Hi,

I've been working with Python for a bit now but I just came accross a
problem and I'm not sure how to approach it. I'd like to convert a text
string into binary data format. I though I'd use the struct module and
the pack function but I can't get it to work. I'm using Python 2.3.3 in
Windows XP.

Thanks in advance for the help,
Oriana
 
S

Stefan =?UTF-8?B?TsOkd2U=?=

Hi,

I've been working with Python for a bit now but I just came accross a
problem and I'm not sure how to approach it. I'd like to convert a text
string into binary data format. I though I'd use the struct module and
the pack function but I can't get it to work. I'm using Python 2.3.3 in
Windows XP.

Why don't you post some pieces of your code ?
Maybe someone can help you fix it.

Stefan
--
 
P

Peter Hansen

Hi,

I've been working with Python for a bit now but I just came accross a
problem and I'm not sure how to approach it. I'd like to convert a text
string into binary data format. I though I'd use the struct module and
the pack function but I can't get it to work. I'm using Python 2.3.3 in
Windows XP.

Examples of what you have as input and expect as output would be useful.
Keep in mind that the term "binary data" is quite ambiguous. Python
"text strings", for example, are already stored as "binary data"
according to my definitions of both things... you will need to explain
what you are trying to accomplish in more words than that.

(Hint: if this is for sending data across a network, note that in Python
"strings" can contain any bytes from 0 to 255, so perhaps they are
already in the "binary" form that you need.)

-Peter
 
J

John Machin

Hi,

I've been working with Python for a bit now but I just came accross a
problem and I'm not sure how to approach it. I'd like to convert a text
string into binary data format. I though I'd use the struct module and
the pack function but I can't get it to work.

"string to binary" tends to suggest "unpack", not "pack".

For example, you have read a 6-byte string from a file. You know that
it contains 3 x 2-byte unsigned integers in little-endian order.

From binary to string:
I'm using Python 2.3.3 in
Windows XP.

It's quite irrelevant to your question, but is there any good reason
why you're not using 2.4.1? If you *really* need to be on 2.3.x,
consider x == 5 -- that's 2 lots of bugfixes and IIRC a security patch
later than 2.3.3.

Cheers,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,237
Messages
2,571,190
Members
47,827
Latest member
wyton

Latest Threads

Top