[Tutor] read text file in zip archive, process, plot

Andreas Kostyrka andreas at kostyrka.org
Sun Apr 15 14:39:29 CEST 2007


* Washakie Wyoming <washakie at juno.com> [070415 14:25]:
> Thank you both! That seems to make my code much more clear... I thought
> it was foolish writing files, but I just couldn't determine how to
> parse the data!
> 
> Kent, one thing, regarding:
>         x = []
>         t = []
>         for l in data[stind:-1]:
>                 l = l.split()  # Split on whitespace
>                 tval = float(l[0])
>                 t.append(tval)
>                 xval = float(l[24])
>                 x.append(xval)
> 
> note that I had to change to [stind:-1] I believe I must have a blank
> line at the end of the file...
That depends upon the platform. Under Unix, files are meant to be
ending in a \n, so you get an empty line at the end. But nobody
enforces that.

So personally, I'd probably add something like this to the loop:
       l = l.split()
       if not l:
           continue

This way the loop ignores empty lines.

Andreas


More information about the Tutor mailing list