[Python-Dev] New syntax for 'dynamic' attribute access (original) (raw)
Larry Hastings larry at hastings.org
Mon Feb 12 16:33:44 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 ]
Ben North wrote:
Jack Jansen:
To me self.[methodname] = self.metadata.[methodname] looks better: what we're doing here is more like dictionary lookup than calling functions. In the same way, though, would this be viewed as too similar to normal dictionary/list indexing? I think that's its strength; it's pleasantly symmetric to using [] on a dict:
dict attribute behavior
--------------------------------
[] .[] pulls out named thing, throws exception
on failure, no default, is an lvalue
.get() .getattr() pulls out named thing, returns default
value on error (specifiable as second
argument), not an lvalue
List comprehensions look like funny lists, generator expressions look like funny expressions, I see no reason why attribute dereferencing shouldn't look like funny dict dereferencing.
+1.
What would the reaction be to obj.{member} instead? Braces are already used to construct dictionaries, so this has some of the right connotations. -0.5. You're not constructing anything, you're looking up something.
For the record, I'm also -1 on the two-argument form--this isn't a function call.
/larry/
- 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 ]