[Python-ideas] Keyword/Symbol literals

Guido van Rossum guido at python.org
Wed Jan 21 20:13:38 CET 2015


On Wed, Jan 21, 2015 at 11:11 AM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:

>
> On Wed, Jan 21, 2015 at 12:42 PM, Guido van Rossum <guido at python.org>
> wrote:
>
>> There's no way adding something like this today will suddenly change
>> everything else that is part of having "symbols"; the proposed feature
>> would be lacking the integration with the internals that makes it work well
>> in some other languages.
>
>
> Wouldn't it be possible to simply have
>
> def Symbol(str):
>     def __new__(cls_, *args):
>         istr = sys.intern(str(*args))
>         return str.__new__(cls, istr)
>
> and have sys.intern() return Symbol instances at some point?  I don't see
> any obvious compatibility problems.
>

I don't see any obvious advantages either.


> How would this be different from adding bool as a subclass of int some
> time ago?
>

Lack of a use case?


> BTW, I think Pandas found [1] the way to have memory-saving string vectors
> without having a symbol type in the core.
>
> [1] http://pandas-docs.github.io/pandas-docs-travis/categorical.html
>

Great.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150121/4f76e07a/attachment.html>


More information about the Python-ideas mailing list