I am trying to make this script work but it's... giving me indentation errors
#!/usr/bin/env python
import io
myfile = open('stats.txt', 'r')
dan = myfile.readline()
print dan
print "Your name: " + dan.split('|')[0]
try:
myfile.write('blah')
finally:
myfile.close()
except IOError:
Help?
exceptneeds to be at the same indentation level astry, and afterexceptyou need an indented block. And what is the linef.close()supposed to close? There is nof.exceptneeds to come beforefinally. Also,myfile = open('stats.txt', 'r')should be inside thetryas well, because it will generate an IOError if the file does not exist or cannot be opened.