Reading a file, sans whitespace
Uri
phrogeeb at hotmail.com
Sun May 23 03:27:10 EDT 2004
> Tim Daneliuk wrote:
> > Say you have read a line in the above format into variable 's'.
> > Then,
> >
> > l = s.split()
> >
> > will return a list containing each of the fields of the line as
> > an entry with the whitespace stripped out. Then,
> >
> > VarName = l[0]
> > VarDate = l[1]
> > VarTime = l[2]
> > VarCo = l[3]
> > VarEmp = l[4]
>
> D'oh! That's much better than the regular expression solution I posted.
>
> The regular expression split is good to know about for more complicated
> patterns, but for simple whitespace splitting there's no need for it.
>
> Thanks,
>
> -Mike
Thanks guys! Tim's idea seems like the easiest for a newbie to
implement, but I'll play around with Mike's pre-compiling thing, too.
I don't really understand what the compile part does, could you
expound upon that?
Thanks for all your help guys!
More information about the Python-list
mailing list