Skip to content Skip to sidebar Skip to footer

Convert And Save String To Binary File In Python

I'm using PyOBEX to exchange binary files (e.g. images etc.) between my computer (Windows 7) and my phone (Android). However, when I use get() to get a file from my phone, it arriv

Solution 1:

In python 2.7 strings represent raw bytes (this changes in python 3)

You simply need to save the data to a binary type file:

withopen('file.jpg', 'wb') as handle:
    handle.write(data_string)

Here is a link to the python doc on open:

https://docs.python.org/2/library/functions.html#open

Note that the "b" represents binary.

Again, this is assuming Python 2.7

Post a Comment for "Convert And Save String To Binary File In Python"