Python 3.2: How to pass a dictionary into str.format()

This does the job:

stats = { 'copied': 5, 'skipped': 14 }
print( 'Copied: {copied}, Skipped: {skipped}'.format( **stats ) )  #use ** to "unpack" a dictionary

For more info please refer to:

  • http://docs.python.org/py3k/library/string.html#format-examples
    and
  • http://docs.python.org/py3k/tutorial/controlflow.html#keyword-arguments

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)