Date: Tue, 24 Aug 2004 11:58:14 +0100 (BST) From: =?iso-8859-1?q?Max=20Russell?= <max_russell2000@yahoo.co.uk> To: freebsd-python@freebsd.org Subject: Splitting elements on a line? Message-ID: <20040824105814.36955.qmail@web25408.mail.ukl.yahoo.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040824105814.36955.qmail>
