This commit is contained in:
Marc Beninca 2024-09-13 17:13:16 +02:00
parent 3e0d5bf2bc
commit aa1f06c20f
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -56,15 +56,16 @@ def read_file(file_path: str):
return file_object.read()
def read_file_lines(file_path: str, charset=CHARSET):
def read_file_lines(file_path: str, charset:str=CHARSET):
return read_file_text(file_path).split(os.linesep)
def read_file_text(file_path: str, charset=CHARSET):
def read_file_text(file_path: str, charset:str=CHARSET):
return read_file(file_path).decode(charset)
def wipe(path: str):
def wipe(path: str) -> None:
"""Wipe provided path, whether directory or file."""
try:
shutil.rmtree(path)
except NotADirectoryError:
@ -73,6 +74,7 @@ def wipe(path: str):
pass
def write(file_path: str, text: str, charset=CHARSET):
def write(file_path: str, text: str, charset:str=CHARSET) -> None:
"""Write text into a file."""
with open(file_path, "bw") as file_object:
file_object.write(text.encode(charset))