hope you are having a great day!
In my recent ventures with Python 3.8.5 I have come across a dilemma I must say... Being that I am a fairly new programmer I am afraid that I don't have the technical knowledge to load a single (BIG) file into the program.
To make my question much more understandable lets look at this down below:
- Lets say that there is a file on my system called "File.mp4" or "File.txt" (1GB in size);
- I want to load this file into my program using the open function as rb;
- I declared a buffer size of 1024;
This is the part I don't know how to solve
- I load 1024 worth of bytes into the program
- I do whatever I need to do with it
- I then load another 1024 bytes in the place of the old buffer
- Rinse and repeat until the whole file has been ran trough.
I looked at this question but either it is not good for my case or I just don't know how to implement it -> link to the question
This is the whole code you requested:
BUFFER = 1024
with open('file.txt', 'rb') as f:
while (chunk := f.read(BUFFER)) != '':
print(list(chunk))