Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Created July 20, 2022 00:32
Show Gist options
  • Save kissgyorgy/b54bf78f199241e5cdc55abe9adc5118 to your computer and use it in GitHub Desktop.
Save kissgyorgy/b54bf78f199241e5cdc55abe9adc5118 to your computer and use it in GitHub Desktop.
Python: use prefix in a string.Template
from string import Template
class EnvTemplate(Template):
"""Substitute variables regularly, but environment variables need "env." prefix,
and only with the braced syntax.
For example: ${env.HOME} works, but $env.HOME does nothing.
"""
braceidpattern = rf"(?:env\.)?{Template.idpattern}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment