[Tutor] Newbie self-introduction + little encoding problem

Twily zanshou at wanadoo.fr
Mon Dec 29 08:11:45 EST 2003


Hello ^_^

I'm Twily, French, 22 years old... I've juste begun to learn programming,
and consequently, Python is the first language I'm trying to master.
I'm currently studying with the textbook "Apprendre  programmer avec
Python" by Gérard Swinnen (adaptation from "How to think like a computer
scientist"), and I have a little problem with ex 23...so I was wondering if
someone here could help me...

The aim of the exercise is to combine two lists
t1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
and
t2 =
['Janvier','Fevrier','Mars','Avril','Mai','Juin','Juillet','Aout','Septembre
','Octobre','Novembre','Decembre']
in a new list, which contains alternatively elements from t1 & t2 (31,
'Janvier', 28, 'Fevrier', etc...)

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']
>>>

As you can see, the accents go completely wrong...
It doesn't change anything to add
# -*- coding: iso-8859-1 -*-
at the beginning of the program (utf-8 doesn't work either). Nonetheless, if
I specify the encoding in the first line of the source, if I then add one
line like this
>>> print "Février"
below the exercise, the accents are printed properly.
So, it seems that the problem lies in forcing the Latin encoding to work for
strings included into lists...is there a (simple ?) way to do this ? ^^;

Thank you very much ^_^

Twily




More information about the Tutor mailing list