Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created October 19, 2017 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JadenGeller/7652a797139fd38b01c8eef4ee5c8ceb to your computer and use it in GitHub Desktop.
Save JadenGeller/7652a797139fd38b01c8eef4ee5c8ceb to your computer and use it in GitHub Desktop.
DynamicDict
#!/usr/bin/python
import string
class DynamicDict:
def __init__(self, function):
self._function = function
def __getitem__(self, key):
return self._function(key)
temp = string.Template("I think that $Jaden is $cool.")
print(temp.substitute(DynamicDict(lambda x: x + "ooo")))
# -> I think that Jadenooo is coolooo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment