Splitting elements on a line?

Max Russell max_russell2000 at yahoo.co.uk
Tue Aug 24 07:47:53 PDT 2004


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


More information about the freebsd-python mailing list