Answers for "create a file if it not exesists"

0

create a file if it not exesists

import os

file_path = r'E:\pynative\account\profit.txt'
if os.path.exists(file_path):
    print('file already exists')
else:
    # create a file
    with open(file_path, 'w') as fp:
        # uncomment if you want empty file
        fp.write('This is first line')
Posted by: Guest on August-21-2021

Code answers related to "create a file if it not exesists"

Browse Popular Code Answers by Language