Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-23 Thread Eric Smith
On 02/22/2011 07:32 PM, Eric Smith wrote: On 2/22/2011 6:28 PM, Steve Holden wrote: On Feb 22, 2011, at 3:08 PM, Eric Smith wrote: Quoting PEP 3101: An example of the 'getitem' syntax: My name is {0[name]}.format(dict(name='Fred')) It should be noted that the use of 'getitem' within a

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-23 Thread Nick Coghlan
On Wed, Feb 23, 2011 at 9:32 AM, Senthil Kumaran orsent...@gmail.com wrote: Because keys are not quote-delimited, it is not possible to    specify arbitrary dictionary keys (e.g., the strings 10 or    :-]) from within a format string. I was curious as to whether or not nested substitution

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-23 Thread R. David Murray
On Tue, 22 Feb 2011 19:32:56 -0500, Eric Smith e...@trueblade.com wrote: You are correct, I didn't exactly implement the PEP on this point, probably as a shortcut. I think there's an issue somewhere that discusses this, but I can't find it. The CPython implementation is really using If

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-23 Thread Eric Smith
On 02/23/2011 09:42 AM, R. David Murray wrote: On Tue, 22 Feb 2011 19:32:56 -0500, Eric Smithe...@trueblade.com wrote: You are correct, I didn't exactly implement the PEP on this point, probably as a shortcut. I think there's an issue somewhere that discusses this, but I can't find it. The

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-23 Thread Steve Holden
On Feb 23, 2011, at 5:42 AM, Nick Coghlan wrote: Ah, how (much more) confused would we be if we didn't have the PEPs and mailing list archives to remind ourselves of what we were thinking years ago... True. And how much more useful it would be if it were incorporated into the documentation

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-23 Thread Ethan Furman
Eric Smith wrote: On 2/22/2011 6:28 PM, Steve Holden wrote: On Feb 22, 2011, at 3:08 PM, Eric Smith wrote: Quoting PEP 3101: An example of the 'getitem' syntax: My name is {0[name]}.format(dict(name='Fred')) It should be noted that the use of 'getitem' within a format string is much

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-23 Thread Eric Smith
On Feb 23, 2011, at 5:42 AM, Nick Coghlan wrote: Ah, how (much more) confused would we be if we didn't have the PEPs and mailing list archives to remind ourselves of what we were thinking years ago... True. And how much more useful it would be if it were incorporated into the documentation

[Python-Dev] Fwd: deep question re dict as formatting input

2011-02-22 Thread Steve Holden
One of the students on an introductory Python 3 class asks a very good question about string formatting. This could be because the course materials are misleading, so I would like to understand. It would appear from tests that {0[X]}.format(...) first tries to convert the string X to in

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-22 Thread Alexander Belopolsky
On Tue, Feb 22, 2011 at 6:01 PM, Steve Holden st...@holdenweb.com wrote: ... It would appear from tests that {0[X]}.format(...) first tries to convert the string X to in integer. If it succeeds then __getitem__() is called with the integer as an argument, otherwise it is called with the string

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-22 Thread Eric Smith
Quoting PEP 3101: An example of the 'getitem' syntax: My name is {0[name]}.format(dict(name='Fred')) It should be noted that the use of 'getitem' within a format string is much more limited than its conventional usage. In the above example, the string 'name' really is the literal

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-22 Thread Steve Holden
On Feb 22, 2011, at 3:08 PM, Eric Smith wrote: Quoting PEP 3101: An example of the 'getitem' syntax: My name is {0[name]}.format(dict(name='Fred')) It should be noted that the use of 'getitem' within a format string is much more limited than its conventional usage. In the

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-22 Thread Senthil Kumaran
On Tue, Feb 22, 2011 at 6:01 PM, Steve Holden st...@holdenweb.com wrote: ... It would appear from tests that {0[X]}.format(...) first tries to convert the string X to in integer. If it succeeds then __getitem__() is called with the integer as an argument, otherwise it is called with the

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-22 Thread Terry Reedy
On 2/22/2011 6:32 PM, Senthil Kumaran wrote: On Tue, Feb 22, 2011 at 6:01 PM, Steve Holdenst...@holdenweb.com wrote: ... It would appear from tests that {0[X]}.format(...) first tries to convert the string X to in integer. If it succeeds then __getitem__() is called with the integer as an

Re: [Python-Dev] Fwd: deep question re dict as formatting input

2011-02-22 Thread Eric Smith
On 2/22/2011 6:28 PM, Steve Holden wrote: On Feb 22, 2011, at 3:08 PM, Eric Smith wrote: Quoting PEP 3101: An example of the 'getitem' syntax: My name is {0[name]}.format(dict(name='Fred')) It should be noted that the use of 'getitem' within a format string is much more limited