What is the best way in the xonsh
shell to loop over the lines of a text file?
(A) At the moment I'm using
for l in !(cat file.txt):
line = l.strip()
# Do something with line...
(B) Of course, there is also
with open(p'file.txt') as f:
for l in f:
line = l.strip()
# Do something with line...
I use (A) because it is shorter, but is there anything even more concise? And preferably folding the l.strip()
into the loop?
Note: My main interest is conciseness (in the sense of a small character count) - maybe using xonsh's special syntax features if that helps the cause.