[Tutor] How parse files in function of number of lines

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Thu May 29 11:12:02 CEST 2014


On 28.05.2014 21:16, jarod_v6 at libero.it wrote:
> Dear all!
> I have two example files:
> tmp.csv:
> name	value	root
> mark	34	yes
>
> tmp2.csv
> name	value	root
>
>
> I want to print a different text if I have more than one row and if I have
> only one row. My code is this:
> with open("tmp.csv") as p:
>      header =p.next()

in general, DON'T use the next method, but the next() function (or 
readline as Alan suggested):
header = next(p)

this will work also in python3, where the next method is gone.

Wolfgang



More information about the Tutor mailing list