[Python-ideas] list of reserved identifiers in program?
Steven D'Aprano
steve at pearwood.info
Fri Oct 26 11:42:25 CEST 2012
On 26/10/12 20: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.
The usual convention is that leading underscores are private, and
trailing underscores are used to avoid name clashes with reserved words.
So myinstance.assert_ rather than myinstance._assert, which would be
considered "private, do not use".
--
Steven
More information about the Python-ideas
mailing list