Python Exception Handling IOError -
i'm trying write simple pything code try open file not exist, handle exception buy displaying "cannot open, no such directory or file" suggestions on i'm doing incorrect?
import sys try: f = open("h:\\nosuchdirectory\\nosuchfile.txt","w") # not modify line except ioerror: print('cannot open, no such directory or file') f.write("this grape file") # not modify line f.close() # not modify line
the initial piece of code started is:
f = open("h:\\nosuchdirectory\\nosuchfile.txt","w" # not modify line f.write("this grape file") # not modify line f.close() # not modify line
Comments
Post a Comment