[Python-ideas] Verbatim names (allowing keywords as names)
Antoine Pitrou
solipsis at pitrou.net
Wed May 16 05:59:32 EDT 2018
On Wed, 16 May 2018 09:13:52 +0100
Paul Moore <p.f.moore at gmail.com> wrote:
> On 16 May 2018 at 01:41, Steven D'Aprano <steve at pearwood.info> wrote:
> > Inspired by Alex Brault's post:
> >
> > https://mail.python.org/pipermail/python-ideas/2018-May/050750.html
> >
> > I'd like to suggest we copy C#'s idea of verbatim identifiers, but using
> > a backslash rather than @ sign:
> >
> > \name
> >
> > would allow "name" to be used as an identifier, even if it clashes with
> > a keyword.
>
> I'm missing something. How is that different from using a trailing
> underscore (like if_ or while_) at the moment? I understand that foo
> and \foo are the same name, whereas foo and foo_ are different, but
> how would that help?
I think it could help in cases like namedtuple, where names can be
part of a data description (e.g. coming from a database) and then used
for attribute access. I do not find it extremely pretty, but I like it
much better still than the "allowing keywords as names" proposal.
It also has the nice side-effect that it doesn't make it easier to add
new keywords, since the common spelling (e.g. `np.where`) would still
become a syntax error and therefore break compatibility with existing
code.
Regards
Antoine.
More information about the Python-ideas
mailing list