String formatting for complex writing systems

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Jun 27 03:47:19 EDT 2007


En Wed, 27 Jun 2007 04:20:52 -0300, Andy <fukazawa at gmail.com> escribió:

> I'm writing a piece of software for some Thai friend.  At the end it
> is supposed to print on paper some report with tables of text and
> numbers.  When I test it in English, the columns are aligned nicely,
> but when he tests it with Thai data, the columns are all crooked.
>
> The problem here is that in the Thai writing system some times two or
> more characters together might take one single space, for example งิ
> (u"\u0E07\u0E34").  This is why when I use something like u"%10s"
> % ..., it just doesn't work as expected.
>
> Is anybody aware of an alternative string format function that can
> deal with this kind of writing properly?

The same thing happens even in English if you print using a proportional  
width font, a "W" is usually wider than an "i" or "l" letter.
You could use a reporting library or program (like ReportLab, generating  
PDF files), but perhaps the simplest approach is to generate an HTML page  
containing a table, and display and print it using your favorite browser.

-- 
Gabriel Genellina



More information about the Python-list mailing list