Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to write binary data to file and socket

Reply
Thread Tools

Re: How to write binary data to file and socket

 
 
Steve Holden
Guest
Posts: n/a
 
      12-12-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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Program to open a file in binary, skip X bytes and write the rest ofthe file to a new file scad C++ 4 05-28-2009 08:47 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
Reading binary socket data and copying to another socket ? swebb99@gmail.com Java 7 11-14-2007 01:51 PM



Advertisments