'open' is not defined

ltc.hotspot at gmail.com ltc.hotspot at gmail.com
Thu Jul 30 20:00:22 EDT 2015






Hi Everyone:




Why is open not defined in the following code:NameError: name 'open' is not defined




Code reads as follows:







fname = raw_input("Enter file name: ")
if len(fname) < 1 : fname = "mbox-short.txt"
fh = open(fname)
count = 0
for line in fh:
    if not line.startswith('From'): continue
    line2 = line.strip()
    line3 = line2.split()
    line4 = line3[1]
    print line4
    count = count + 1            
print "There were", count, "lines in the file with From as the first word"







Regards,

Hal






Sent from Surface
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150731/9ac120b0/attachment.html>


More information about the Python-list mailing list