Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52205
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: right adjusted strings containing umlauts |
| Date | 2013-08-08 15:50 +0000 |
| References | <mailman.352.1375972418.1251.python-list@python.org> <9781df99-f9c8-4217-aa67-7a714b7f2ebe@googlegroups.com> <5203B841.4060304@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.357.1375977051.1251.python-list@python.org> (permalink) |
Kurt Mueller wrote:
> Am 08.08.2013 16:43, schrieb jfharden@gmail.com:
>> On Thursday, 8 August 2013 15:23:46 UTC+1, Kurt Mueller wrote:
>>> I'd like to print strings right adjusted.
>>> print( '>{0:>3}<'.format( 'ä' ) )
>>
>> Make both strings unicode
>> print( u'>{0:>3}<'.format( u'ä' ) )
>> Why not use rjust for it though?
>> u'ä'.rjust(3)
>
> In real life there is a list of strings in output_list from a command like:
> output_list = shlex.split( input_string, bool_cmnt, bool_posi, )
> input_string is from a file, bool_* are either True or False
> repr( output_list )
> ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
> which should be printed right aligned.
> using:
> print( u'{0:>3} {1:>3} {2:>3} {3:>3} {4:>3}'.format( *output_list ) )
> ( In real life, the alignement and the width is variable )
>
> How do I prepare output_list the pythonic way to be unicode strings?
> What do I do, when input_strings/output_list has other codings like iso-8859-1?
>
In general, when reading from an outside device like a file, convert to
unicode immediately, while you still know the encoding used in that
particular file. Then after all processing, worry about alignment only
when you're about to output the string. And at that point, you're
subject to the quirks of the font as well as the quirks of the
encoding of the terminal.
As MRAB has pointed out, sometimes two code points are used to represent
a single character which will end up taking a single column. Likewise
sometimes a single code point will take more than one "column" to
display. Ideograms are one example, but a font which is not fixed pitch
is another.
If you're going to a standard terminal, all you can do is get close.
This is why there are special functions for gui's to help with
alignment.
--
DaveA
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