How to upload a file line by line in Nim?

I want to upload a large file line by line to Nim. I tried the following code snippet:

for line in lines "largefile.txt":
  echo line

However, this loads the entire file largefile.txtinto memory, which is not possible if the file is very large> 30 GB.

How can I iterate over a large file while keeping only one line in memory?

+4
source share
1 answer

Indeed, Raymer Berends is right. The function is linesworking properly.

The problem was that there were only newlines in my file. As a result, Nim (correctly) reads the file as one large line.

+3
source

Source: https://habr.com/ru/post/1665329/


All Articles