On 05/06/2014 10:33 AM, James Swift wrote: > Hi, > > In 3.3 I could do the following > >>>> "{x:s}".format(**{'x': [1, 2, 3]}) > '[1, 2, 3]' > > But in 3.4 > >>>> "{x:s}".format(**{'x': [1, 2, 3]}) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: non-empty format string passed to object.__format__ > > > Is this intentional? Yes. See http://bugs.python.org/issue7994 for the rationale. You can use: >>> "{x!s:15s}".format(**{'x': [1, 2, 3]}) '[1, 2, 3] ' That is, convert it first to a string (with !s) then use whatever string formatting specifier you want (here, '15s'). This should work under all 3.x versions (I think, haven't checked). BTW, for this specific case, you might want to use format_map: >>> "{x!s:15s}".format_map({'x': [1, 2, 3]}) '[1, 2, 3] ' Eric.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4