How to write binary data to file and socket

Steve Holden steve at holdenweb.com
Fri Dec 12 08:22:28 EST 2008


Lee Soin wrote:
> Hello, all!
> I'm new to python. In Linux C programming, writing data to file and
> socket share the same system call "write". But it seems that only data
> of string type can be used for "write" and "send". So how to write
> binary data to file and socket?
> 
Assuming you are using Python 2.x, use the struct module to convert your
data to a string, then write that.

In Python 3.x you would use the bytes type.

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list