Answers for "open and append to file python if exists if not create"

11

python create file if not exists

import os

if not os.path.exists(path):
    with open(path, 'w'):
Posted by: Guest on May-09-2020
0

open and append to file python if exists if not create

import os
filename="file.txt"
answ=os.path.exists(filename)
with open(filename, "a" if answ else "w") as f:
    if(answ):
        f.write("\n")
    f.write("hi!")
Posted by: Guest on April-05-2021

Code answers related to "open and append to file python if exists if not create"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language