I have a text file just say
text1 text2 text text
text text text text
I am looking to firstly count the number of strings in the file (all deliminated by space) and then output the first two texts. (text 1 text 2)
Any ideas?
Thanks in advance for the help
Edit: This is what I have so far:
>>> f=open('test.txt')
>>> for line in f:
print line
text1 text2 text text text text hello
>>> words=line.split()
>>> words
['\xef\xbb\xbftext1', 'text2', 'text', 'text', 'text', 'text', 'hello']
>>> len(words)
7
if len(words) > 2:
print "there are more than 2 words"
The first problem I have is, my text file is: text1 text2 text text text
But when i pull the output of words I get: ['\xef\xbb\xbftext1', 'text2', 'text', 'text', 'text', 'text', 'hello']
Where does the '\xef\xbb\xbf come from?