Skip to content

Instantly share code, notes, and snippets.

@jaseg
Created May 26, 2015 11:12
Show Gist options
  • Save jaseg/1ce39aa6ee73dbfd97d0 to your computer and use it in GitHub Desktop.
Save jaseg/1ce39aa6ee73dbfd97d0 to your computer and use it in GitHub Desktop.
Basic string interpolation in pure python
# alike https://github.com/lihaoyi/macropy#string-interpolation
In [23]: class Interpol:
def __getitem__(self, str):
import inspect
return str.format(**inspect.currentframe().f_back.f_locals)
....:
In [24]: s = Interpol()
In [25]: a = 23
In [26]: b = 42
In [27]: s["Hail Eris! {a} {b}"]
Out[27]: 'Hail Eris! 23 42'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment