Encode differences between idle python and python

P

pretoriano_2001

Hello:
Under win32 XP y select python command line and execute next code with
results indicated:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
using python IDLE I repeat the code, but get next differen result:
IDLE 1.2
What do you think is happending and how can I solve this ? The IDLE
looks fine but command line has problems.
 
P

Peter Otten

ßÚݾ·

That means that Python is better at guessing the correct encoding than you
are. Here's how you can make it share its secrets:
'UTF-8' # something else on your machine (cp850, maybe)

Then you can use that encoding to print:
áéíóú

On the other hand: why not always print the unicode string directly?

Peter
 
G

Gabriel Genellina

At said:
Hello:
Under win32 XP y select python command line and execute next code with
results indicated:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on
Type "help", "copyright", "credits" or "license" for more information.

Because the console code page != windows code page.
Exit Python. At the console prompt, type:
If it says 850 - your console is using codepage 850.
Enter Python again, and replace 'latin-1' with
'cp850'. You should get the right representation.


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
P

pretoriano_2001

Gabriel, Peter:
Many thanks for your clear answers!!
Best regards.

Vizcayno
 
N

Neil Cerutti

Gabriel, Peter:
Many thanks for your clear answers!! Best regards.

Something I've been working on is currently using the following
trick:

# Create some string of non-ASCII text in ISO 8859-1.
some_string = ''.join(chr(a) for a in range(0xc0, 0xdf)).decode('ISO 8859-1')
# Print it to stdout, converting to the terminal's encoding, replacing
# unprintable characters with '?'.
print some_string.encode(sys.stdout.encoding, 'replace')
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top