[Python-ideas] string codes & substring equality

spir denis.spir at gmail.com
Fri Nov 29 09:08:50 CET 2013


On 11/29/2013 07:56 AM, Greg Ewing wrote:
> spir wrote:
>> I thought you (Greg) meant users (like me) who parse or scan strings piecemeal
>> could build a list of 1-char strings before starting:
>
> No, I meant that there would be a built-in cache operating
> behind the scenes, so that whenever you index a string and
> the resulting character has been extracted from a string
> before, you'd get the cached object instead of a new one.
>
> The advantage would be that no new functions or methods
> are needed.
>
>> But isn't it easier (and cheaper and more "intuitive") just to have a method
>> like s.code(i)?
>
> It would help with code that use single-char strings for
> more purposes than just taking the ord() of them.

You are right on this. However, both features (1-char string interning and 
extending the func ord to ord(s,i)) are somewhat independant (and in any case 
compatible).

Denis


More information about the Python-ideas mailing list