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
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'
>
>
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 '
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