[Python-ideas] Keyword/Symbol literals

Matthew Rocklin mrocklin at gmail.com
Wed Jan 21 06:20:43 CET 2015

It would be nice to have literal keywords/symbols.  By this I mean, terms
that look like words but are not previously defined variables.

*Prior art*

Some other languages prefix by colon, :foo,  or use a backtick,  `foo.

julia> :foo
julia> typeof(:foo)

user=> :foo
user=> (type :foo)

user=> `foo
user=> (type `foo)

*Why is this useful?*

One use case in NumPy/Pandas use is to specify columns or fields of data
without resorting to strings.  E.g.

df = pandas.load(...)

*What do people do now?*

Currently people use auto-generated attributes


or strings


auto-generated attributes work great until you want to use chained


strings work but feel unpleasant

*Prior discussion?*

This is a common language construct so my guess is that it has come up
before.  Sadly Google searching the terms *keywords* and *symbols* results
it a lot of unrelated material.  Can anyone point me to previous discussion?

There are clearly issues with using :foo in that it overlaps with slice
syntax, presumably some other character could be pressed into service if
this was found worthwhile.

I can come up with more motivating use cases if desired.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150120/4130e6da/attachment-0001.html>

More information about the Python-ideas mailing list