Problem with format string and unicode

Discussion in 'Python' started by Hans Martin, Mar 28, 2008.

  1. Hans Martin

    Hans Martin Guest

    Hi,

    this is probably a trivial problem, but a google search for "python"
    and "unicode" and" format string" gives too many hits: If I specify
    e.g. "%20s" in a format string and the string value contains UTF-8
    stuff (differing number of bytes per character), the length of the
    resulting string (in characters) varies. How can I fix this?

    Many thanks in advance!

    --
    Psssst! Schon vom neuen GMX MultiMessenger gehört?
    Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
     
    Hans Martin, Mar 28, 2008
    #1
    1. Advertisements

  2. On Fri, 28 Mar 2008 21:13:00 +0100, Hans Martin wrote:

    > this is probably a trivial problem, but a google search for "python"
    > and "unicode" and" format string" gives too many hits: If I specify
    > e.g. "%20s" in a format string and the string value contains UTF-8
    > stuff (differing number of bytes per character), the length of the
    > resulting string (in characters) varies. How can I fix this?


    Use unicode strings instead.

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Mar 28, 2008
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timiun
    Replies:
    1
    Views:
    644
    Joerg Jooss
    Dec 24, 2003
  2. Brian Candy
    Replies:
    2
    Views:
    1,448
    Janaka
    Feb 18, 2004
  3. Pekka Niiranen
    Replies:
    1
    Views:
    393
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Sep 21, 2004
  4. Gabriele *darkbard* Farina

    Unicode digit to unicode string

    Gabriele *darkbard* Farina, May 16, 2006, in forum: Python
    Replies:
    2
    Views:
    717
    Gabriele *darkbard* Farina
    May 16, 2006
  5. Holger Joukl
    Replies:
    5
    Views:
    730
    Ben Finney
    Dec 13, 2006
  6. ankur
    Replies:
    1
    Views:
    14,430
    Jan =?UTF-8?B?VGhvbcOk?=
    Aug 27, 2007
  7. Chirag Mistry
    Replies:
    6
    Views:
    390
    Ollivier Robert
    Feb 8, 2008
  8. Chris Angelico
    Replies:
    3
    Views:
    405
    Mark Lawrence
    Mar 1, 2013
Loading...