I have searched for an answer. I am sure they are out there, but there are way too many false hits.
This is my script (my attempt fails):
#!/bin/env python
import re
usage="""
My favorite restaurant is <<<res>>>
My favorite person is <<<per>>>
"""
res="pizza hut"
per="my sister"
def main():
value = re.sub(r'<<<(\w+)>>>', globals()[r'\1'], usage)
print 'value=%s.' % (value)
if ( __name__ == "__main__"):
main()
What I am trying to output is:
value=
My favorite restaurant is pizza hut
My favorite person is my sister
.
The closest answer that I have seen, involves maintaining a separate list. I do not want to have to maintain a separate list.
globals()here? There is no global name\1in your code (nor could there be).