Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: right adjusted strings containing umlauts Date: 8 Aug 2013 14:40:27 GMT Organization: Norwich University Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net V4p3kmLTl8JMuj5FpG7FGw7ArxB6GF4+GIzcqnCZjwoDxt/yOQ Cancel-Lock: sha1:2lscuScawnTmQHlLU8deJp/YnJk= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: csiph.com comp.lang.python:52199 On 2013-08-08, Kurt Mueller wrote: > I'd like to print strings right adjusted. > ( Python 2.7.3, Linux 3.4.47-2.38-desktop ) > > from __future__ import print_function > print( '>{0:>3}<'.format( 'a' ) ) >> a< > > But if the string contains an Umlaut: > print( '>{0:>3}<'.format( '??' ) ) >> ??< > > Same with % notation: > print( '>%3s<' % ( 'a' ) ) >> a< > print( '>%3s<' % ( '??' ) ) >> ??< > > For a string with no Umlaut it uses 3 characters, but for an > Umlaut it uses only 2 characters. > > I guess it has to to with unicode. > How do I get it right? You guessed it! Use unicode strings instead of byte strings, e.g., u"...". -- Neil Cerutti