I have code that creates a folder and puts the output files into it. I want to use the try-except-else block and the rewrite option, which can be set to True or False, so if the folder already exists and the overwrite is set to false, it just prints out that the folder already exists, and in In all other cases, it will be executed without comment.
The only solution I came up with is:
def function( parameters, overwrite = False ):
try:
os.makedirs( dir )
except OSError:
if overwrite:
data making code...
else:
print dir + ' already exists, skipping...'
else:
if overwrite:
data making code...
, ? , , , ? , C Pythonic.