-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor file handling functions in helpers.py
- Loading branch information
Showing
1 changed file
with
7 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
import os | ||
|
||
|
||
def create_directory(directory): | ||
""" | ||
Creates a directory if it doesn't exist. | ||
""" | ||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
|
||
|
||
def read_file(file_path): | ||
""" | ||
Reads the contents of a file and returns them as a string. | ||
""" | ||
with open(file_path, 'r') as file: | ||
with open(file_path, "r") as file: | ||
return file.read() | ||
|
||
|
||
def write_file(file_path, content): | ||
""" | ||
Writes the given content to a file. | ||
""" | ||
with open(file_path, 'w') as file: | ||
with open(file_path, "w") as file: | ||
file.write(content) | ||
|
||
|
||
def delete_file(file_path): | ||
""" | ||
Deletes a file if it exists. | ||
""" | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
os.remove(file_path) |