Skip to content

Instantly share code, notes, and snippets.

@javadba
Last active May 20, 2019 06:10
Show Gist options
  • Select an option

  • Save javadba/5552140 to your computer and use it in GitHub Desktop.

Select an option

Save javadba/5552140 to your computer and use it in GitHub Desktop.
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
Copy link
Copy Markdown
Author

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