[Python-Dev] New syntax for 'dynamic' attribute access (original) (raw)
Guido van Rossum guido at python.org
Tue Feb 13 06:14:45 CET 2007
- Previous message: [Python-Dev] New syntax for 'dynamic' attribute access
- Next message: [Python-Dev] New syntax for 'dynamic' attribute access
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2/12/07, Maric Michaud <maric at aristote.info> wrote:
Le mardi 13 février 2007 01:36, Barry Warsaw a écrit: > On Feb 12, 2007, at 7:32 PM, Guido van Rossum wrote: > > Oh, now I am definitely in favor of .[]! I read it in gmail in FireFox > > which uses a small variable-pitch font whose dot is a single pixel. > > The .() example was hard to find; the .[] jumped out immediately. > > (When do you ever see self[anything]?) > > Raymond's -> suggestion was nice. > I really dislikes the .[ or .( or .{ operators. Just on my mail editor the two expressions
a.[b] and a,[b] are quite hard to differentiate while completely unrelated.
Yeah, so are 1.2 and 1,2. This is why the style guide (PEP 8) insists on a space after a comma but not after a period.
Why did the brace syntax wasn't even discussed ? Seems clean to me.
Because they are arbitrary -- if x{y} or x.{y} would be acceptable, why not x. or x.|y| or x./y/? Or indeed why not x at y? (Not that I'm in favor of that. :-)
That x.[y] and x.(y) resemble x[y] and x(y) is an advantage of the proposed new notation, not a disadvantage; the new operator is semantically closer to x[y] than to x(y) so x.[y] makes sense.
obj{expr} can be read as "given obj as a namespace, retrieve the name resulting by expr in obj and enclosing namespaces (supers)".
Yeah, it can just as well be read as "call obj with 2**expr as argument". Also, your reference to enclosing namespaces and supers is misplaced -- this should map to the existing getattr operation, which can have many different semantics depending on the type of obj.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] New syntax for 'dynamic' attribute access
- Next message: [Python-Dev] New syntax for 'dynamic' attribute access
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]