Skip to content

Instantly share code, notes, and snippets.

@javadba javadba/gist:5552140
Last active May 20, 2019

Embed
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"
tostr(s)
@javadba

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.