[issue17447] str.identifier shouldn't accept Python keywords

Florent Xicluna report at bugs.python.org
Sun Mar 17 19:38:04 CET 2013


Florent Xicluna added the comment:

According to the documentation, the reserved words are classified as identifiers:
http://docs.python.org/3/reference/lexical_analysis.html#keywords

There's an easy workaround:

>>> from keyword import iskeyword
>>> def is_valid_identifier(s):
...     return s.isidentifier() and not iskeyword(s)
... 
>>> is_valid_identifier('def')
False

----------
nosy: +flox

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17447>
_______________________________________


More information about the Python-bugs-list mailing list