indexing in format strings
Mark Lawrence
breamoreboy at yahoo.co.uk
Fri Apr 11 17:43:59 EDT 2014
On 11/04/2014 22:33, blindanagram wrote:
> With:
>
> l = [1,2,3]
>
> this:
>
> print('{0[0]:d}..{0[2]:d}'.format(l))
>
> gives 1..3 but this:
>
> print('{0[0]:d}..{0[-1]:d}'.format(l))
>
> gives:
>
> Traceback (most recent call last):
> File "<string>", line 1, in <fragment>
> builtins.TypeError: list indices must be integers, not str
>
> which seems to me counterintuitive.
>
> I expected indexing in a format string to behave as it does elsewhere
> but this seems not to be true.
>
See http://bugs.python.org/issue7951
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
More information about the Python-list
mailing list