Skip to content

Instantly share code, notes, and snippets.



Last active May 20, 2019
What would you like to do?
Concise string interpolation in python
def tostr(msg, inhash=locals()):
import io
outstr = io.StringIO()
print(outstr, msg % inhash)
return outstr.getvalue()
usage example:
s="Some message from %(froma)s \n on the %(day)d of %(month)s %(year)d \n Says %(message)s\n"
froma="Steven Iceberg" ; day=15; month="September"; year=1987; message="I'm thinking of doing another Indiana Jones Movie"

This comment has been minimized.

Copy link
Owner Author

@javadba javadba commented May 20, 2019

updated to python3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment