Print formatted Strings with Umlauts

Joerg Lehmann joerg.lehmann at mail.com
Thu Feb 12 19:42:12 CET 2004


"Martin v. Löwis" <martin at v.loewis.de> wrote in message news:<c0f8tb$5iu$05$1 at news.t-online.com>...
> Joerg Lehmann wrote:
> > I am using Python 2.2.3 (Fedora Core 1). ...
> > I have tried to set the encoding in site.py to 'latin-1', but it did not change
> > my results. Is there no way to store umlauts in 1 byte??? 
> 
> There is, but Fedora Core 1 does not use it. Instead, it uses an
> encoding where an umlaut character needs two bytes (namely, UTF-8).
> Changing site.py does not change the way your system represents
> these characters.
> 
> > What is the right way
> > to print strings containing umlauts in a tabular way (same field width)?
> 
> As Jeff explains: In the specific case, using Unicode strings would
> help. He is also right that, in general, it is very difficult to find
> out how many columns a single character uses, as some characters have
> width 0, and other characters have width 2 (in a mono-spaced terminal;
> for variable-spaced output, adding space characters to achieve
> formatting will never work reliably).
> 
> Regards,
> Martin

I have found a fix myself, I'm not sure if this is "the right way",
but it solves my problem:

I changed the settings in /etc/sysconfig/i18ln from UTF-8 to
ISO-8859-1:

LANG="en_US.ISO-8859-1"
SUPPORTED="en_US.ISO-8859-1:en_US:en"
SYSFONT="latarcyrheb-sun16"

This fixed my problem, Umlauts are stored in one byte now.

Thanks for your inspirations.

PS: Installing Python 2.3 (rpm for Fedora from www.python.org) did not
help.
--
Joerg Lehmann



More information about the Python-list mailing list