Welcome, guest | Sign In | My Account | Store | Cart
# Auto-prints a string using the new (as of 2.4) string-template
# based substitution.
import copy, inspect
from string import Template

def printfmt(template):
    frame = inspect.stack()[1][0]
    try:
        var = copy.copy(frame.f_globals)
        var.update(frame.f_locals)
        print Template(template).safe_substitute(var)
    finally:
        del frame

History

  • revision 3 (16 years ago)
  • previous revisions are not available