Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'string.': 0.05; 'string': 0.09; 'e.g.,': 0.09; 'python': 0.11; 'kurt': 0.12; '__future__': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'unicode.': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'unicode': 0.24; 'header:In-Reply-To:1': 0.27; 'linux': 0.33; 'guess': 0.33; 'actual': 0.34; "i'd": 0.34; 'could': 0.34; 'received:84': 0.35; 'but': 0.35; 'right?': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; "you're": 0.61; 'it!': 0.67; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'characters,': 0.84; 'guessed': 0.84; 'reply- to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=ZMDuxxLb c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=0kkAYlmtguIA:10 a=aPlvBj4zpMQA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=1nf95dA6l6IA:10 a=pGLkceISAAAA:8 a=sWXL8zicxZFYE-RPbysA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 X-AUTH: mrabarnett:2500 Date: Thu, 08 Aug 2013 16:19:38 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: python-list@python.org Subject: Re: right adjusted strings containing umlauts References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375975172 news.xs4all.nl 15867 [2001:888:2000:d::a6]:50267 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52202 On 08/08/2013 15:40, Neil Cerutti wrote: > 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"...". > It also matters which actual codepoints you're using in the Unicode string. You could have u'ä', which is one codepoint (u'\xE4' or u'\N{LATIN SMALL LETTER A WITH DIAERESIS}'), or u'ä', which two codepoints (u'a\u0308' or u'\N{LATIN SMALL LETTER A}\N{COMBINING DIAERESIS}').