What is the best solution to process each line of a text file whose size is about 500 MB?
The proposal to which I had thought :
def files(mon_fichier):
while True:
data = mon_fichier.read(1024)
if not data:
break
yield data
fichier = open('tonfichier.txt', 'r')
for bloc in files(fichier):
print bloc
Thank you in advance
with open('myfile.txt') as inf:
for line in inf:
# do something
pass
Just using the standard file operations should work as long as you keep away from readlines and instead just use readline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With