I have a file in which lines are separated using a delimeter say .
. I want to read this file line by line, where lines should be based on presence of .
instead of newline.
One way is:
f = open('file','r')
for line in f.read().strip().split('.'):
#....do some work
f.close()
But this is not memory efficient if my file is too large. Instead of reading a whole file together I want to read it line by line.
open
supports a parameter 'newline' but this parameter only takes None, '', '
', '
', and '
'
as input as mentioned here.
Is there any way to read files line efficiently but based on a pre-specified delimiter?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…