Binary file IO in python, where to start?

前端 未结 3 1404
暖寄归人
暖寄归人 2020-12-28 20:55

As a self-taught python hobbyist, how would I go about learning to import and export binary files using standard formats?

I\'d like to implement a script that takes

相关标签:
3条回答
  • 2020-12-28 21:28

    If you want to construct and analyse binary files the struct module will give you the basic tools, but it isn't very friendly, especially if you want to look at things that aren't a whole number of bytes.

    There are a few modules that can help, such as BitVector, bitarray and bitstring. (I favour bitstring, but I wrote it and so may be biased).

    For parsing binary formats the hachoir module is very good, but I suspect it's too high-level for your current needs.

    0 讨论(0)
  • 2020-12-28 21:43

    You should probably start with the struct module, as you pointed to in your question, and of course, open the file as a binary.

    Basically you just start at the beginning of the file and pick it apart piece by piece. It's a hassle, but not a huge problem. If the files are compressed or encrypted, things can get more difficult. It's helpful if you start with a file that you know the contents of so you're not guessing all the time.

    Try it a bit, and maybe you'll evolve more specific questions.

    0 讨论(0)
  • 2020-12-28 21:44

    For teaching yourself python tools that work with binary files, this will get you going. Fun too. Exercises with binaries, zips, images... lots more.

    0 讨论(0)
提交回复
热议问题