text strings to binary...

Peter Hansen peter at engcorp.com
Tue May 3 17:18:20 EDT 2005


oriana.falco at thalesesec.com wrote:
> 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



More information about the Python-list mailing list