Bug? Feature? setattr(foo, '3', 4) works!
Ben Finney
ben+python at benfinney.id.au
Fri Dec 19 07:23:39 EST 2014
Cem Karan <cfkaran2 at gmail.com> writes:
> However, the following doesn't work:
>
> >>> foo.3
> File "<stdin>", line 1
> foo.3
> ^
> SyntaxError: invalid syntax
> >>> bar.3
> File "<stdin>", line 1
> bar.3
> ^
> SyntaxError: invalid syntax
>
> I'd like to suggest that getattr(), setattr(), and hasattr() all be
> modified so that syntactically invalid statements raise SyntaxErrors.
What syntactically invalid statements? The only syntactically invalid
statements I see you presenting are ones that *already* raise
SyntaxError.
I think you mean that setting an attribute on an object should be a
SyntaxError if the resulting attribute's name is not a valid identifier.
But why should a valid statement produce SyntaxError?
I'm −1 on such a change.
--
\ “Education is learning what you didn't even know you didn't |
`\ know.” —Daniel J. Boorstin, historian, 1914–2004 |
_o__) |
Ben Finney
More information about the Python-list
mailing list