[Tutor] Newbie self-introduction + little encoding problem

Karl Pflästerer sigurd at 12move.de
Mon Dec 29 14:03:55 EST 2003


On 29 Dec 2003, Twily <- zanshou at wanadoo.fr wrote:

> The program I've written works perfectly if I use no French accents at all.
> However, if I add accents at "Février", "Août", and "Décembre", as it should
> be the case to write months' names in French, here is what I obtain when I
> run the program :


> [31, 'Janvier', 28, 'F\xe9vrier', 31, 'Mars', 30, 'Avril', 31, 'Mai', 30,
> 'Juin', 31, 'Juillet', 31, 'Ao\xfbt', 30, 'Septembre', 31, 'Octobre', 30,
> 'Novembre', 31, 'D\xe9cembre']

(that's a repost; it seems the first e-mail got lost).

But that's right.  Did you try to print such a string?

> As you can see, the accents go completely wrong...

They don't.  You simple see the intern representation of the strings.

>>>> print "Février"
> below the exercise, the accents are printed properly.

In [23]: mon = [31, 'Janvier', 28, 'F\xe9vrier', 31, 'Mars', 30, 'Avril', 31, 'Mai', 30,
   ....: m 'Juin', 31, 'Juillet', 31, 'Ao\xfbt', 30, 'Septembre', 31, 'Octobre', 30,
   ....:    'Novembre', 31, 'D\xe9cembre']

In [24]: for d, m in zip(mon[::2], mon[1::2]):
   ....:     print "%s %s" % (d, m)
   ....:     
31 Janvier
28 Février
31 Mars
30 Avril
31 Mai
30 Juin
31 Juillet
31 Août
30 Septembre
31 Octobre
30 Novembre
31 Décembre

If you can read German there is a good FAQ which might help you to
understand what happens:
           http://p-nand-q.com/python/unicode_faq.html


   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list