Linked Questions
71 questions linked to/from Reading binary file and looping over each byte
41
votes
4
answers
30k
views
What is the idiomatic way to iterate over a binary file?
With a text file, I can write this:
with open(path, 'r') as file:
for line in file:
# handle the line
This is equivalent to this:
with open(path, 'r') as file:
for line in iter(file....
0
votes
3
answers
2k
views
How do you process binary files in Python [duplicate]
We had DataInputStream for processing binary files in Java; what can we use for these files in Python?
-2
votes
2
answers
2k
views
An iterator for reading a file byte by byte [duplicate]
Is there an iterator for reading a file byte by byte?
0
votes
1
answer
2k
views
python send mail with zip attachment fails on Windows [duplicate]
I'm writing some code that writes a zip file to the file system, and then sends that zip file as an attachment in an email. Code used to create the message and attach the file is:
msg = MIMEMultipart(...
0
votes
1
answer
811
views
How to read binary files in Python? [duplicate]
I am new to binary files and trying to figure out how to read and manipulate them. I have the following code:
bfile = open('square.bmp', 'wb')
b = bytearray(bfile.read(bn))
while len(b) > 0:
...
0
votes
1
answer
446
views
Python len(file.read()) != C# System.IO.File.ReadAllText(path).Length [duplicate]
I try to save a matrix of rgb pixel in file with C# and read it in python.
If my image is 243*507, then the len of the file must be (height * width * rgb) then 243*507*3 (I save each rgb value as a ...
179
votes
8
answers
570k
views
Reading a binary file with python
I find particularly difficult reading binary file with Python. Can you give me a hand?
I need to read this file, which in Fortran 90 is easily read by
int*4 n_particles, n_groups
real*4 group_id(...
38
votes
5
answers
173k
views
How to read a file byte by byte in Python and how to print a bytelist as a binary? [closed]
I'm trying to read a file byte by byte, but I'm not sure how to do that. I'm trying to do it like that:
file = open(filename, 'rb')
while 1:
byte = file.read(8)
# Do something...
So does that ...
9
votes
3
answers
4k
views
How to read in one character at a time from a file in python?
I want to read in a list of numbers from a file as chars one char at a time to check what that char is, whether it is a digit, a period, a + or -, an e or E, or some other char...and then perform ...
13
votes
3
answers
52k
views
Python writing binary files, bytes
Python 3. I'm using QT's file dialog widget to save PDFs downloaded from the internet. I've been reading the file using 'open', and attempting to write it using the file dialog widget. However, I've ...
11
votes
3
answers
66k
views
Python: Read hex from file into list?
Is there a simple way to, in Python, read a file's hexadecimal data into a list, say hex?
So hex would be this:
hex = ['AA','CD','FF','0F']
I don't want to have to read into a string, then split. ...
10
votes
2
answers
55k
views
Python how to read raw binary from a file? (audio/video/text)
I want to read the raw binary of a file and put it into a string. Currently I am opening a file with the "rb" flag and printing the byte but it's coming up as ASCII characters (for text that is, for ...
8
votes
5
answers
20k
views
Reading an entire binary file into Python
I need to import a binary file from Python -- the contents are signed 16-bit integers, big endian.
The following Stack Overflow questions suggest how to pull in several bytes at a time, but is this ...
11
votes
5
answers
76k
views
How to open a .data file extension
I am working on side stuff where the data provided is in a .data file. How do I open a .data file to see what the data looks like and also how do I read from a .data file programmatically through ...
7
votes
2
answers
30k
views
xor each byte with 0x71
I needed to read a byte from the file, xor it with 0x71 and write it back to another file. However, when i use the following, it just reads the byte as a string, so xoring creates problems.
f = open('...