I have an ASCII file, which is essentially a grid of 16-bit integers; The file size on disk is about 300 MB. I do not need to read the file in memory, but I need to save its contents as a single container (s), so for the initial testing of memory use, I tried list
and tuples
as internal containers with an external container always as list
through list comprehension:
with open(file, 'r') as f:
for _ in range(6):
t = next(f)
grid = [line.strip().split() for line in f]
grid = [tuple(line.strip().split()) for line in f]
Having discussed the use of the grid among the command, I need to save it as a list of lists up to a certain point, after which I will convert it to a list of tuples for running the program.
What I'm interested in is how a 300 MB file can have its own lines stored in a container container, and its total size should be 10 times the original file size. Does each container really take up so much space to hold one line?
source
share