[Python-ideas] .pyu nicode syntax symbols (was Re: Empty set, Empty dict)

Andrew Barnert abarnert at yahoo.com
Tue Jul 1 12:23:19 CEST 2014


> On Tuesday, July 1, 2014 2:08 AM, Chris Angelico <rosuav at gmail.com> wrote:

> > On Tue, Jul 1, 2014 at 7:00 PM, Andrew Barnert
> 
> <abarnert at yahoo.com.dmarc.invalid> wrote:
>>      src = src.replace('∅', '_EMPTY_SET_LITERAL')
> 
> Note that this suffers from a flaw that my POC script also suffers
> from: it replaces this character *anywhere*, rather than only when
> it's being used as a symbol on its own. Even inside a literal string.
> It might be necessary to replace it back the other way afterward,
> somehow, but I'm not sure if that would work.


Yes, that's easy. Also, _EMPTY_SET_LITERAL_ itself could exist in your source (after all, it exists in my source fragment right above, right?), but that's easy too. See https://github.com/abarnert/emptyset for a slapped-together implementation that solves both those problems (except for bytes literals, but it explains how to do that). If it prints out "set() is the empty set ∅", then it worked; it successfully replaced the ∅ in your source with an empty set literal, and left the ∅ in your format string as ∅.


More information about the Python-ideas mailing list