[Tutor] Mailbox

Alan Gauld alan.gauld at btinternet.com
Thu Jul 30 09:26:21 CEST 2015


On 29/07/15 22:55, ltc.hotspot at gmail.com wrote:

> #top of code, initialize variable
> output_list = ["default"]
>
> #rest of code
> print output_list
> ['default']
>
> Raw Data File:

Note, this is the code not the data...

> count = 0
> fname = raw_input("Enter file name: ")
> if len(fname) < 1 : fname = "mbox-short.txt"
> for line in fname:

You are still looping over the filename not the file contents.
thus line will take the values: m, b, ,o, x -, s, h,....

>      line = line.strip()
>      if not line.startswith('From '): continue

And this will always be true so the loop will stop here.

>      line = line.split()
> count = count + 1

this is outside the loop so will always be 1

> print len(line)
> fh = open(fname)

this opens the file but you do nothing with it.

> print "There were", count, "lines in the file with From as the first word"

You do not seem to have changed anything from your
original post. All the same errors are still there.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list