osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Grapheme clusters, a.k.a.real characters


On Tue, 18 Jul 2017 10:11:39 -0400, Random832 wrote:

> On Fri, Jul 14, 2017, at 04:15, Marko Rauhamaa wrote:
>>  Consider, for example, a Python source code
>> editor where you want to limit the length of the line based on the
>> number of characters more typically than based on the number of pixels.
> 
> Even there you need to go based on the width in character cells. Most
> characters for East Asian languages occupy two character cells.
> 
> It would be nice if there was an easy way to get str.format to use this
> width instead of the length in code points for the purpose of padding.

You could always put in a feature request :-)


Alternatively, you could propose yet another formatting function that 
groks the difference between narrow width and full width characters. The 
reason I suggest that is that I expect it will probably be easier to 
implement one yourself in pure Python, and add it to the string module, 
than to convince somebody else to modify str.format() which is in C.

:-)


-- 
Steve