Re: Python String Formatting - passing both a dict and string to .format()

2013-11-26 Thread Michael Torrie
On 11/26/2013 05:01 PM, Victor Hooi wrote: > Hi, > > I'm trying to use Python's new style string formatting with a dict > and string together. > > For example, I have the following dict and string variable: > > my_dict = { 'cat': 'ernie', 'dog': 'spot' } foo = 'lorem ipsum' > > If I want to jus

Re: Python String Formatting - passing both a dict and string to .format()

2013-11-26 Thread Chris Kaynor
On Tue, Nov 26, 2013 at 4:01 PM, Victor Hooi wrote: > Hi, > > I'm trying to use Python's new style string formatting with a dict and > string together. > > For example, I have the following dict and string variable: > > my_dict = { 'cat': 'ernie', 'dog': 'spot' } > foo = 'lorem ipsum' > >

Re: Python String Formatting - passing both a dict and string to .format()

2013-11-26 Thread Steven D'Aprano
On Tue, 26 Nov 2013 16:01:48 -0800, Victor Hooi wrote: > '{0['cat']} {1} {0['dog']}'.format(my_dict, foo) ... > SyntaxError: invalid syntax It's a syntax error because you are using the same quotes. You have: '{0['cat']} {1} {0['dog']}' which is parsed as: STR '{0[' NAME cat STR '

Python String Formatting - passing both a dict and string to .format()

2013-11-26 Thread Victor Hooi
Hi, I'm trying to use Python's new style string formatting with a dict and string together. For example, I have the following dict and string variable: my_dict = { 'cat': 'ernie', 'dog': 'spot' } foo = 'lorem ipsum' If I want to just use the dict, it all works fine: '{cat} and {do