Template
import os
from string import Template
def verify_file_exists(file_path):
if not os.path.exists(file_path):
raise FileNotFoundError(f"The file {file_path} does not exist.")
def templatize(template_file_path):
verify_file_exists(template_file_path)
with open(template_file_path, 'r') as file:
template_content = file.read()
template = Template(template_content)
# Use os.environ to get the environment variables
output = template.substitute(os.environ)
with open('/tmp/out', 'w') as out_file:
out_file.write(output)
print(output)
''
if __name__ == "__main__":
# Replace 'path_to_your_template_file' with the actual path of your template file
# Requires NAME to be set in the environment
templatize('/Users/nickolaykondratyev/git_repos/my-python-sandbox/data/template_example.txt')
Backlinks