Python Forum
How do I read and write a binary file in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I read and write a binary file in Python?
#4
Python does not have unsigned types. It has bytes, but no shorts or longs. Those are C types. Python types are unsized.

If you need to work with C-type values you can use the ctypes library.

https://docs.python.org/3/library/ctypes.html

Or you can use the struct library.

https://docs.python.org/3/library/struct.html

I think the struct library sounds like a better fit for what you describe.
Reply


Messages In This Thread
RE: How do I read and write a binary file in Python? - by deanhystad - May-30-2023, 03:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 29,222 May-20-2025, 12:26 PM
Last Post: hanmen9527
  How to write variable in a python file then import it in another python file? tatahuft 4 1,149 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 1,460 Dec-19-2024, 11:57 AM
Last Post: snippsat
  [SOLVED] [Linux] Write file and change owner? Winfried 6 1,852 Oct-17-2024, 01:15 AM
Last Post: Winfried
  python read PDF Statement and write it into excel mg24 1 1,134 Sep-22-2024, 11:42 AM
Last Post: Pedroski55
  Read TXT file in Pandas and save to Parquet zinho 2 1,485 Sep-15-2024, 06:14 PM
Last Post: zinho
  Pycharm can't read file Genericgamemaker 5 1,890 Jul-24-2024, 08:10 PM
Last Post: deanhystad
  Python is unable to read file Genericgamemaker 13 4,589 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Delete file with read-only permission, but write permission to parent folder cubei 6 26,191 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 3,609 May-03-2024, 07:23 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020