Getting strange characters in the command prompt

S

sebb

For information, I have windows xp (english edition).

When I use special non-english characters (like é à è ...) in my
python code, IDLE tells me to add a line like:

# -*- coding: cp1252 -*-

.... because of the presence of non-ASCII characters.

When I write a script like the folowing:

# -*- coding: cp1252 -*-
print "é à è"

.... and I run it in the windows command prompt, I get strange
characters I didn't ask for.

And when I write those non-English characters (é à è) directly in the
command prompt, I get the correct characters.

Can anyone help we with that problem?
 
I

Irmen de Jong

sebb wrote:

[...]
... and I run it in the windows command prompt, I get strange
characters I didn't ask for.

And when I write those non-English characters (é à è) directly in the
command prompt, I get the correct characters.

Can anyone help we with that problem?

Does executing

chcp 1252

before running your python program help?
The windows console is not set to code page 1252 by default
as far as I know, but some other windows-specific encoding.

--Irmen
 
M

Martin v. Loewis

sebb said:
# -*- coding: cp1252 -*-
print "é à è"

... and I run it in the windows command prompt, I get strange
characters I didn't ask for.
[...]
Can anyone help we with that problem?

As Irmen explains, this is because cmd.exe uses code page 850
(on your installation). You should write

print u"é à è"

Regards,
Martin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top