Last active
May 20, 2019 06:10
-
-
Save javadba/5552140 to your computer and use it in GitHub Desktop.
Concise string interpolation in 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
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated to python3