On 2013-12-04 21:33, Chris Angelico wrote:
> I don't think so. What the OP asked for was:
> 
> my_object.'valid-attribute-name-but-not-valid-identifier'
> 
> Or describing it another way: A literal string instead of a token.
> This is conceivable, at least, but I don't think it gives any
> advantage over a dictionary.

In both cases (attribute-access-as-dict-functionality and
attribute-access-as-avoiding-setattr), forcing a literal actually
diminishes Python's power.  I like the ability to do

  a[key.strip().lower()] = some_value
  setattr(thing, key.strip().lower(), some_value)

which can't be done (?) with mere literal notation.  What would they
look like?

  a.(key.strip().lower()) = some_value

(note that "key.strip().lower()" not actually a "literal" that
ast.literal_eval would accept). That's pretty ugly, IMHO :-)

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to