Splitting elements on a line?
Max Russell
max_russell2000 at yahoo.co.uk
Tue Aug 24 10:22:12 PDT 2004
P.S:
sorry about the whole "c:\" business. Protype is on
Windows. Boo Hiss.
--- Max Russell <max_russell2000 at yahoo.co.uk> wrote:
> Hello-
> If I have a file made up of lines like this:
>
> one two three
> four five six
> seven eight nine
>
> how can I read the individual items into a lit, so
> that I do not get each list item consisting of
> something like:
> "one two three"
>
> Currently I have this:
> import os, os.path, random
> filename = ("C:\list.txt")
> file = open(filename,"r")
> word_list = file.readlines()
> file.close()
> print word_list
>
> # output from this program has format ['one two
> three\n', 'four five six']
> # therefore- need to split each item into individual
> compenents
> # also- need to remove whitespace and newline
> character
>
> So:
>
> Would I perform a split after all of the above?
>
> Would I be better performing the split before
> reading
> the items into the list?
>
> thanks
> Max
>
>
>
>
>
>
___________________________________________________________ALL-NEW
> Yahoo! Messenger - all new features - even more fun!
> http://uk.messenger.yahoo.com
> _______________________________________________
> freebsd-python at freebsd.org mailing list
>
http://lists.freebsd.org/mailman/listinfo/freebsd-python
> To unsubscribe, send any mail to
> "freebsd-python-unsubscribe at freebsd.org"
>
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
More information about the freebsd-python
mailing list