Created
May 26, 2015 11:12
-
-
Save jaseg/1ce39aa6ee73dbfd97d0 to your computer and use it in GitHub Desktop.
Basic string interpolation in pure python
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
# 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