f=/tmp/test
if not os.path.exists(os.path.dirname(f)):
os.makedirs(os.path.dirname(f)
with open(f, "a+") as f:
f.write("\ntest")
python check if file exists if not create
Leave a reply
f=/tmp/test
if not os.path.exists(os.path.dirname(f)):
os.makedirs(os.path.dirname(f)
with open(f, "a+") as f:
f.write("\ntest")