Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52202

Re: right adjusted strings containing umlauts

Date 2013-08-08 16:19 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: right adjusted strings containing umlauts
References <mailman.352.1375972418.1251.python-list@python.org> <b6hourF5uu0U1@mid.individual.net>
Newsgroups comp.lang.python
Message-ID <mailman.354.1375975172.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 08/08/2013 15:40, Neil Cerutti wrote:
> On 2013-08-08, Kurt Mueller <kurt.alfred.mueller@gmail.com> 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}').

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

right adjusted strings containing umlauts Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2013-08-08 16:23 +0200
  Re: right adjusted strings containing umlauts Neil Cerutti <neilc@norwich.edu> - 2013-08-08 14:40 +0000
    Re: right adjusted strings containing umlauts MRAB <python@mrabarnett.plus.com> - 2013-08-08 16:19 +0100
  Re: right adjusted strings containing umlauts jfharden@gmail.com - 2013-08-08 07:43 -0700
    Re: right adjusted strings containing umlauts Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2013-08-08 17:24 +0200
      Re: right adjusted strings containing umlauts Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-10 01:29 +0000
    Re: right adjusted strings containing umlauts Peter Otten <__peter__@web.de> - 2013-08-08 17:44 +0200
    Re: right adjusted strings containing umlauts Dave Angel <davea@davea.name> - 2013-08-08 15:50 +0000
    Re: right adjusted strings containing umlauts Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2013-08-08 18:16 +0200
    Re: right adjusted strings containing umlauts Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2013-08-08 18:27 +0200
      Re: right adjusted strings containing umlauts wxjmfauth@gmail.com - 2013-08-09 01:30 -0700
    Re: right adjusted strings containing umlauts Peter Otten <__peter__@web.de> - 2013-08-08 18:34 +0200
    Re: right adjusted strings containing umlauts Chris Angelico <rosuav@gmail.com> - 2013-08-08 17:37 +0100
    Re: right adjusted strings containing umlauts Dave Angel <davea@davea.name> - 2013-08-08 17:47 +0000
    Re: right adjusted strings containing umlauts Terry Reedy <tjreedy@udel.edu> - 2013-08-08 16:51 -0400
    Re: right adjusted strings containing umlauts Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2013-08-23 17:47 +0200
    Re: right adjusted strings containing umlauts Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2013-08-28 10:01 +0200
    Re: right adjusted strings containing umlauts Dave Angel <davea@davea.name> - 2013-08-28 10:23 +0000
      Re: right adjusted strings containing umlauts kurt.alfred.mueller@gmail.com - 2013-08-28 04:17 -0700

csiph-web