Why is there no natural syntax for accessing attributes with names not being valid identifiers?

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 4 03:57:28 EST 2013


On Tue, Dec 3, 2013 at 11:31 PM, rusi <rustompmody at gmail.com> wrote:
> Its a more fundamental problem than that:
> It emerges from the OP's second post) that he wants '-' in the attributes.
> Is that all?
>
> Where does this syntax-enlargement stop? Spaces? Newlines?

At non-strings.

>>> setattr(foo, 21+21, 42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: attribute name must be string, not 'int'



More information about the Python-list mailing list