I am learning programming with Python. I am not sure if I can write a try/except block like this.
import os
import shutil
try:
shutil.rmtree('c:/guna/newCAT1')
print("dir newCAT1 deleted")
except:
os.mkdir('c:/guna/newCAT1')
print("dir newCAT1 created")
fileIN=open('c:/guna/newCAT1/secretMSG.txt','w' )
fileIN.writelines("the dog is green")
fileIN.close()
else:
print("exception code did not execute")
os.mkdir('c:/guna/newCAT1')
print("dir newCAT1 created")
fileIN = open('c:/guna/newCAT1/secretMSG.txt', 'w')
fileIN.writelines("the dog is green")
fileIN.close()