using binary in python
Christian Gollwitzer
auriocus at gmx.de
Wed Nov 11 16:32:18 EST 2015
Am 10.11.15 um 22:29 schrieb kent nyberg:
> On Mon, Nov 09, 2015 at 10:20:25PM -0800, Larry Hudson via Python-list wrote:
>> Your questions are somewhat difficult to answer because you misunderstand
>> binary. The key is that EVERYTHING in a computer is binary. There are NO
>> EXCEPTIONS, it's all binary ALL the time. The difference comes about in how
>> this binary data is displayed and manipulated. I want to emphasize, ALL the
>> DATA is binary.
>>
>
> Thanks alot for taking the time.
> I get it now. I sort of, but not fully, misunderstood the conecpt of binary files.
> The thing I was after; and the thing Im playing with now after a more succesfull time with google,
> is writing more specific things to a file than just strings.
> English is not my native language so please forgive me, but
> I wanted to write specifc 16bit codes, and read them. And later play with bitwise operations on them. Sort of.
> It might not make sense at all, but hey.. it doesnt have to
I think I understand what you want. Look at the struct module:
https://docs.python.org/2/library/struct.html
You can write/read binary data from files with standard means. Using
struct, you can interpret or format integer values into a specific
binary format. That would allow to create a reader or writer for a given
binary format in Python.
Christian
More information about the Python-list
mailing list