I\'m trying to open a file, and if the file doesn\'t exist, I need to create it and open it for writing. I have this so far:
#open file for reading fn = input(\"
I think this should work:
#open file for reading fn = input("Enter file to open: ") try: fh = open(fn,'r') except: # if file does not exist, create it fh = open(fn,'w')
Also, you incorrectly wrote fh = open ( fh, "w") when the file you wanted open was fn
fh = open ( fh, "w")
fn