Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24670
| From | Josh English <Joshua.R.English@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: format() not behaving as expected |
| Date | 2012-06-29 10:24 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <61b63296-d7d5-4c1f-9055-d4e0c3113cb5@googlegroups.com> (permalink) |
| References | <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> <4fede104$0$29988$c3e8da3$5496439d@news.astraweb.com> |
On Friday, June 29, 2012 10:08:20 AM UTC-7, Steven D'Aprano wrote:
> >>>> c = (1,3)
> >>>> s = "{0[0]}"
> >>>> print s.format(c)
> > '1'
>
> That's not actually the output copied and pasted. You have quotes around
> the string, which you don't get if you pass it to the print command.
>
Mea culpa. I typed it in manually because the direct copy and paste was rather ugly full of errors because of many haplographies.
> >>>> print format(c,s)
> > Traceback (most recent call last):
> > File "<interactive input>", line 1, in <module>
> > ValueError: Invalid conversion specification
> [...]
> > Any idea why one form works and the other doesn't?
>
> Because the format built-in function is not the same as the format string
> method.
...
>
> (Personally, I find the documentation about format to be less than
> helpful.)
>
Thanks. I think it's coming together.
Either way, this format seems uglier than what I had before, and it's longer to type out. I suppose that's just programmers preference.
Josh
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
format() not behaving as expected Josh English <Joshua.R.English@gmail.com> - 2012-06-29 09:31 -0700
Re: format() not behaving as expected MRAB <python@mrabarnett.plus.com> - 2012-06-29 18:02 +0100
Re: format() not behaving as expected Josh English <Joshua.R.English@gmail.com> - 2012-06-29 10:19 -0700
Re: format() not behaving as expected MRAB <python@mrabarnett.plus.com> - 2012-06-29 18:41 +0100
Re: format() not behaving as expected Josh English <Joshua.R.English@gmail.com> - 2012-06-29 10:19 -0700
Re: format() not behaving as expected Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-29 17:08 +0000
Re: format() not behaving as expected Josh English <Joshua.R.English@gmail.com> - 2012-06-29 10:24 -0700
csiph-web