[Tutor] Major newbie question..

alan.gauld@bt.com alan.gauld@bt.com
Fri, 12 Nov 1999 10:33:37 -0000


> This might seem like a lame question, but I'm following a 
> tutorial on a web page, 

Looks suspiciously like mine :-)

> import string
> def numwords(s):
>     list = string.split(s) # need to qualify split() with 
> string module
>     return len(list) # return number of elements in list
> resp = raw_input("Enter a filename :  ")
> 
> inp = resp

But this doesn't.... you need to open the file.
The actual code on the web page reads(minus comments):

import string
def numwords(s):
    list = string.split(s) 
    return len(list) 

inp = open("menu.txt","r")
total = 0  

for line in inp.readlines():
    total = total + numwords(line) 
print "File had %d words" % total

inp.close()

BTW Did you try sending me a mail via the feedback 
link on the web page? I don't recall seeing a 
message about this...

Alan g.