473,734 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encode differences between idle python and python

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.
>>u=u'áéíóú'
u
u'\xe1\xe9\xed\ xf3\xfa'
>>print u
áéíóú
>>a=u.encode('l atin-1')
a
'\xe1\xe9\xed\x f3\xfa'
>>print a
ßÚݾ·
>>type(a)
<type 'str'>
>>type(u)
<type 'unicode'>
>>>
using python IDLE I repeat the code, but get next differen result:
IDLE 1.2
>>u=u'áéíóú'
u
u'\xe1\xe9\xed\ xf3\xfa'
>>print u
áéíóú
>>a=u.encode('l atin-1')
a
'\xe1\xe9\xed\x f3\xfa'
>>print a
áéíóú
>>type(a)
<type 'str'>
>>type(u)
<type 'unicode'>
>>>
What do you think is happending and how can I solve this ? The IDLE
looks fine but command line has problems.

Oct 10 '06 #1
4 2297
pr************* @hotmail.com wrote:
>u=u'áéíóú'
u
u'\xe1\xe9\xed\ xf3\xfa'
>print u
áéíóú
>a=u.encode('la tin-1')
a
'\xe1\xe9\xed\x f3\xfa'
>print a
ßÚݾ·
That means that Python is better at guessing the correct encoding than you
are. Here's how you can make it share its secrets:
>>import sys
sys.stdout.en coding
'UTF-8' # something else on your machine (cp850, maybe)

Then you can use that encoding to print:
>>your_encodi ng = sys.stdout.enco ding
print u"áéíóú".encode (your_encoding)
áéíóú

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

Peter
Oct 10 '06 #2
At Tuesday 10/10/2006 02:44, pr************* @hotmail.com wrote:
>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.
>u=u'áéíóú'
u
u'\xe1\xe9\xed \xf3\xfa'
>print u
áéíóú
>a=u.encode('la tin-1')
a
'\xe1\xe9\xed\ xf3\xfa'
>print a
ßÚݾ·
>type(a)
<type 'str'>
>type(u)
<type 'unicode'>
>>
Because the console code page != windows code page.
Exit Python. At the console prompt, type:
>chcp
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

Oct 10 '06 #3

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

Vizcayno

Oct 10 '06 #4
On 2006-10-10, pr************* @hotmail.com <pr************ *@hotmail.comwr ote:
>
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.enc ode(sys.stdout. encoding, 'replace')

--
Neil Cerutti
That's the biggest laughingstock I've ever heard of in my life.
--Trot Nixon
Oct 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
7386
by: Ashot | last post by:
This is sort of both Python and Vim related (which is why I've posted to both newsgroups). Python related: ---------------------- I have been frustrated for quite some time with a lack of a history command in IDLE (in fact with IDLE in general). Often I'll develop new code at the command line, testing each line as I go. Currently I have to copy and paste, removing outputs and the ">>>" at each line. Is it perhaps possible to make...
75
4660
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the functions are simplified versions of the full featured methods for compiled regular expressions. Most non-trivial applications always use the compiled form UNQUOTE
2
1264
by: Alasdair | last post by:
I've just installed python 2.4.2 from source - it works fine from the command line. But when I attempt to start idle, I am told: ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** I have tcl 8.4 and tk 8.4 on my system; can anybody provide me with some advice? Sorry if this is a FAQ; I've spent some time searching the net for
0
1666
by: h112211 | last post by:
Hi all, I'm using the Windows version of Python 2.4.3 and everything worked okay until I installed PyGreSQL. Well, in fact the installation went fine, but when I try to run my script from IDLE I get: Traceback (most recent call last): File "<pathtomyscript>\main.py", line 3, in -toplevel- import pgdb File "C:\Program Files\Python24\Lib\site-packages\pgdb.py", line 69,
1
1887
by: eastier | last post by:
Hi, I've just read in Python 2.5 description that IDLE 'executes code in a separate process', using a TCP connection on port 127.0.0.1 to communicate. Does it mean that we can now debug embedded python with IDLE ? Thanks for any feedback,
2
3699
by: dhouse | last post by:
I just installed Python 2.5.1, and I see that IDLE is not included. I have spent the last hour trying to find out how to get IDLE, but have had absolutely no success. It is VERY frustrating. Does anyone know how to get IDLE?
1
1498
by: sandro dentella | last post by:
Hi, I'm having a little problem while using python mode. I'm used to hit C-c C-c and have a Python Output buffer opened with the output. Now, on Ubuntu 7.10 and 8.04, C-c C-c sends to the Python buffer that is not raised in a window. I need to hit C-c C-z to see it. First of all I'm puzzled and would like to understand what makes the difference. I guess is some defaults that changed in the system configuration.
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.