Re: How to write binary data to file and socket

Discussion in 'Python' started by Steve Holden, Dec 12, 2008.

  1. Steve Holden

    Steve Holden Guest

    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/
    Steve Holden, Dec 12, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    906
  2. Laszlo Nagy
    Replies:
    1
    Views:
    4,810
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    962
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    542
    Laszlo Nagy
    Feb 1, 2009
  5. Steve Holden
    Replies:
    0
    Views:
    657
    Steve Holden
    Feb 1, 2009
Loading...

Share This Page