Re: right adjusted strings containing umlauts

2013-08-28 Thread kurt . alfred . mueller
On Wednesday, August 28, 2013 12:23:12 PM UTC+2, Dave Angel wrote: > On 28/8/2013 04:01, Kurt Mueller wrote: > > Because I cannot switch to Python 3 for now my life is not so easy:-) > > For some text manipulation tasks I need a template to split lines > > from stdin into a list of strings the way

Re: right adjusted strings containing umlauts

2013-08-28 Thread Dave Angel
On 28/8/2013 04:01, Kurt Mueller wrote: > Because I cannot switch to Python 3 for now my life is not so easy:-) > > For some text manipulation tasks I need a template to split lines > from stdin into a list of strings the way shlex.split() does it. > The encoding of the input can vary. > For furt

Re: right adjusted strings containing umlauts

2013-08-28 Thread Kurt Mueller
Am 08.08.2013 18:37, schrieb Chris Angelico: > On Thu, Aug 8, 2013 at 5:16 PM, Kurt Mueller > wrote: >> Am 08.08.2013 17:44, schrieb Peter Otten: >>> Kurt Mueller wrote: What do I do, when input_strings/output_list has other codings like iso-8859-1? >>> You have to know the actual encodi

Re: right adjusted strings containing umlauts

2013-08-23 Thread Kurt Mueller
Am 08.08.2013 18:37, schrieb Chris Angelico: > On Thu, Aug 8, 2013 at 5:16 PM, Kurt Mueller > wrote: >> Am 08.08.2013 17:44, schrieb Peter Otten: >>> Kurt Mueller wrote: What do I do, when input_strings/output_list has other codings like iso-8859-1? >>> You have to know the actual encodi

Re: right adjusted strings containing umlauts

2013-08-09 Thread Steven D'Aprano
On Thu, 08 Aug 2013 17:24:49 +0200, Kurt Mueller wrote: > What do I do, when input_strings/output_list has other codings like > iso-8859-1? When reading from a text file, honour some sort of encoding cookie at the top (or bottom) of the file, like Emacs and Vim use, or a BOM. If there is no enc

Re: right adjusted strings containing umlauts

2013-08-09 Thread wxjmfauth
Le jeudi 8 août 2013 18:27:06 UTC+2, Kurt Mueller a écrit : > Now I have this small example: > > -- > > #!/usr/bin/env python > > # vim: set fileencoding=utf-8 : > > > > from __future__ import print_function > > import sys, shlex > >

Re: right adjusted strings containing umlauts

2013-08-08 Thread Terry Reedy
On 8/8/2013 11:24 AM, Kurt Mueller wrote: print( u'{0:>3} {1:>3} {2:>3} {3:>3} {4:>3}'.format( *output_list ) ) Using autonumbering feature, same as print( u'{:>3} {:>3} {:>3} {:>3} {:>3}'.format( *output_list ) ) print( (u' '.join([u'{:>3}']*5)).format(*output_list) ) print( (u' '.join([u'{:

Re: right adjusted strings containing umlauts

2013-08-08 Thread Dave Angel
Kurt Mueller wrote: > Now I have this small example: > -- > #!/usr/bin/env python > # vim: set fileencoding=utf-8 : > > from __future__ import print_function > import sys, shlex > > print( repr( sys.stdin.encoding ) ) > > strg_form = u'{0:>3}

Re: right adjusted strings containing umlauts

2013-08-08 Thread Chris Angelico
On Thu, Aug 8, 2013 at 5:16 PM, Kurt Mueller wrote: > Am 08.08.2013 17:44, schrieb Peter Otten: >> Kurt Mueller wrote: >>> What do I do, when input_strings/output_list has other codings like >>> iso-8859-1? >> >> You have to know the actual encoding. With that information it's easy: > output_l

Re: right adjusted strings containing umlauts

2013-08-08 Thread Peter Otten
Kurt Mueller wrote: > Am 08.08.2013 17:44, schrieb Peter Otten: >> Kurt Mueller wrote: >>> What do I do, when input_strings/output_list has other codings like >>> iso-8859-1? >> >> You have to know the actual encoding. With that information it's easy: > output_list >> ['\xc3\xb6', '\xc3\xbc',

Re: right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
Now I have this small example: -- #!/usr/bin/env python # vim: set fileencoding=utf-8 : from __future__ import print_function import sys, shlex print( repr( sys.stdin.encoding ) ) strg_form = u'{0:>3} {1:>3} {2:>3} {3:>3} {4:>3}' for inpt_l

Re: right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
Am 08.08.2013 17:44, schrieb Peter Otten: > Kurt Mueller wrote: >> What do I do, when input_strings/output_list has other codings like >> iso-8859-1? > > You have to know the actual encoding. With that information it's easy: output_list > ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f'] encoding

Re: right adjusted strings containing umlauts

2013-08-08 Thread Dave Angel
Kurt Mueller wrote: > Am 08.08.2013 16:43, schrieb jfhar...@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'ä' ) ) >> W

Re: right adjusted strings containing umlauts

2013-08-08 Thread Peter Otten
Kurt Mueller wrote: > Am 08.08.2013 16:43, schrieb jfhar...@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'ä' ) ) >> W

Re: right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
Am 08.08.2013 16:43, schrieb jfhar...@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

Re: right adjusted strings containing umlauts

2013-08-08 Thread MRAB
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}

Re: right adjusted strings containing umlauts

2013-08-08 Thread jfharden
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) -- Jonathan -- http://mail.python

Re: right adjusted strings containing umlauts

2013-08-08 Thread Neil Cerutti
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( '??' ) ) >> ??< >

right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
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<