-3

Possible Duplicate:
Split string into a list in Python

I have a text text file, 2011 2012 332 1972 ...

I need to access the words of this line (stored in a text file) using some index, could be an array, like a[] should contain contents of a line , where every element of a[] should be a word. Now, when I run a for loop I can access the words of the a[] using some index. like a[0],a[1]. Please suggest some ways...

Community
  • 1
  • 1

1 Answers1

-1

Use code like this:

fh = open("foo")
line = fh.readline()
words = line.split()
Sam Manzer
  • 1,220
  • 10
  • 23
  • I have copied the contents of a read file A into another file B by running a for loop , but how will i be able to retrieve the different words/ strings of a line (assuming for now i just a line in that file)so that i can format it and then write in file B again. – user2033869 Feb 03 '13 at 02:35