setattr
will set names that cannot be used with regular attribute access i.e. obj.name
.
>>> from types import SimpleNamespace
>>> my_instance = SimpleNamespace()
>>> setattr(my_instance, 'from', 0) # works
>>> getattr(my_instance, 'from')
0
>>> my_instance.from
SyntaxError: invalid syntax
How can I check for such names, to avoid using them?