likable / src /utils.py
jens-l's picture
refactor: cleanup and update README.md with new features and usage instructions
f0ca218
raw
history blame contribute delete
602 Bytes
"""
Utility functions shared across the Likable project.
"""
import os
def load_file(path):
"""Load the contents of a file and return as string.
Args:
path: Path to the file to load
Returns:
str: File contents, or empty string if path is None or file doesn't exist
"""
if path is None:
return ""
# Check if file exists first
if not os.path.exists(path):
return ""
# path is a string like "subdir/example.py"
try:
with open(path, encoding="utf-8") as f:
return f.read()
except OSError:
return ""