-2
fileinput = open('tweets.txt', 'r')

for line in fileinput:

   lines = line.lower() 

from this how can I take the whole lines and not only the last?

Joe Kalvos
  • 13
  • 1
  • you overwrite the "lines" every time with the latest one. – Paul Collingwood Jan 04 '13 at 11:29
  • 1
    Vote to close. There are answers to **your** previous very similar question already, here: http://stackoverflow.com/questions/14154787/reading-lines-from-a-file-using-python/14154889#14154889 – miku Jan 04 '13 at 11:29

3 Answers3

0

The following will give you a list:

fileinput = open('tweets.txt', 'r')
lines = [line.lower() for line in fileinput]

If this is not what you're looking for, please clarify your requirements.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
0

The problem is that you are using the assignment operator =.

You need to change this to a += but you will lose the new line character \n.

I would suggest opening a list like this:

fileinput = open('tweets.txt', 'r')

lines = []

for line in fileinput:

   lines.append(line.lower())

Then you will have all lines in a list.

Regards Joe

Joe Doherty
  • 3,778
  • 2
  • 31
  • 37
0

If you want to convert all the lines:

fileinput = open("tweets.txt", "r")
lowered = [l.lower() for l in fileinput]
unwind
  • 391,730
  • 64
  • 469
  • 606