[Python-ideas] list of reserved identifiers in program?
Rob Cliffe
rob.cliffe at btinternet.com
Fri Oct 26 11:33:47 CEST 2012
On 26/10/2012 10:22, Daniel Fetchinson wrote:
> Hi folks,
>
> Would it be a good idea to have a built-in list of strings containing
> the reserved identifiers of python such as 'assert', 'import', etc?
>
> The reason I think this would be useful is that whenever I write a
> class with user defined methods I always have to exclude the reserved
> keywords. So for instance myinstance.mymethod( ) is okay but
> myinstance.assert( ) is not. In these cases I use the convention
> myinstance._assert( ), etc. In order to test for these cases I hard
> code the keywords in a list and test from there. I take the list of
> keywords from http://docs.python.org/reference/lexical_analysis.html#keywords
> But what if these change in the future?
>
> So if I would have a built-in list containing all the keywords of the
> given interpreter version in question my life would be that much
> easier.
>
> What do you think?
>
> Cheers,
> Daniel
>
>
>>> import keyword
>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del',
'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global',
'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',
'raise', 'return', 'try', 'while', 'with', 'yield']
>>>
Rob Cliffe
More information about the Python-ideas
mailing list