Files
MasterarbeitCode/crawl_recipes/tools/write_text.py
2021-04-11 23:28:41 +02:00

24 lines
660 B
Python

import os
import sys
def write_text(input_text, file_path, option="Exit"):
""" Write text to disk checking options if it exists """
if not os.path.exists(file_path):
with open(file_path, 'w') as f:
f.write(input_text.decode("utf-8"))
else:
if option == "Exit":
print("Write file error: This file already exists.\n %s \nExiting..." %(file_path))
sys.exit(1)
elif option == "Append":
with open(file_path, 'a') as f:
f.write(input_text)
elif option == "Overwrite":
with open(file_path, 'w') as f:
f.write(input_text)