When I run this code it prompts for the file name, and regardles whether I enter the path to the file, or drag and drop, it will run the except part of the code 'File cannot be opened' but it will never run fuse = open(fname) or the rest of the program.
Here is the complete program:
fname = raw_input('Enter file name: ')
try:
fuse = open(fname)
except:
print 'File cannot be opened'
raw_input('Press enter to quit')
count = 0
total = 0
for line in fuse:
if line.notstartswith('X-DSPAM-Confidence:'): continue
elif line.startswith('X-DSPAM-Confidence:'):
count = count + 1
vpos = line.find(' ')
addv = line[vpos:]
addv = float(addv)
total = total + addv
print total/count
Any ideas of what could be wrong?
When I run it without the try and except from the command line to see the error, this is the message I get:
Enter file name: "C:\Users\Gonzalez Cocoma\Documents\Python\Programs\mbox-short.txt" Traceback (most recent call last): File "C:\Users\Gonzalez Cocoma\Documents\Python\Programs\Spamaverage.py", line 2, in fuse = open(fname) IOError: [Errno 22] invalid mode ('r') or filename: '"C:\Users\Gonzalez Cocoma\Documents\Python\Programs\mbox-short.txt"'
exceptand haven't reported what the error is.except IOError as e: print einstead.