[Tutor] variable in format string throwing error
Mark Lawrence
breamoreboy at yahoo.co.uk
Tue May 14 01:09:15 CEST 2013
On 13/05/2013 22:51, Jim Mooney wrote:
> I'm trying variable substitution in a format string that looks like one
> that works, but I get an error. What am I doing wrong? tks
>
> x = 40
> s = 'John flew to the {0:-^{x}} yesterday'
> print(s.format('moon', x))
>
> Error is builtins.KeyError: 'x'
>
> --
> Jim
>
Using over complicated modern string formatting? Stick with the old C
style % style and it's much easier. Contrary to popular belief it's not
going away :)
--
If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.
Mark Lawrence
More information about the Tutor
mailing list