Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52199
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: right adjusted strings containing umlauts |
| Date | 2013-08-08 14:40 +0000 |
| Organization | Norwich University |
| Message-ID | <b6hourF5uu0U1@mid.individual.net> (permalink) |
| References | <mailman.352.1375972418.1251.python-list@python.org> |
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"...".
--
Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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