[Tutor] reading lines from a list of files

Peter Otten __peter__ at web.de
Tue May 12 08:48:58 CEST 2015


Alex Kleider wrote:

> Is there a better (more 'Pythonic') way to do the following?
> 
>      for f_name in f_names:
>          with open(f_name, 'r') as f:
>              for line in f:

There's the fileinput module

<https://docs.python.org/dev/library/fileinput.html#fileinput.input>

but personally I prefer the way you show above.



More information about the Tutor mailing list