I want create file safely in python2.7
import os
import sys
logname = "logfile"
f = open(logname, 'w')
sys.stdout = f
print "file created with file name {}".format(logname)
f.close()
Above script will overwrite if file is exist. I dont want to recreate it.
Say if file name "logfile" already exist, try to create with "logfile1" name.