[IronPython] Spanish characters with accents do not see correctly
dinov at exchange.microsoft.com
Tue Jan 24 13:39:29 PST 2006
The problem here is that Python's default encoding is ASCII. You can set the default encoding in the sys class by using the setdefaultencoding API:
and all file I/O will then use that encoding. The preferred way to do this is to update your site.py file to make this call.
After this setdefaultencoding is removed from the sys module. To get it back you need to reload the sys module (something that Beta 1 doesn't support unfortunately).
Also if your file has the UTF headers then we'll automatically recognize those and open the file in the correct format. So if you use Notepad to store the file and do a Save As and choose one of the Unicode encodings then we should be able to properly read the file w/o changing the default encoding.
Hope that helps!
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Paparipote .
Sent: Tuesday, January 24, 2006 12:23 PM
To: users at lists.ironpython.com
Subject: [IronPython] Spanish characters with accents do not see correctly
I have the next text file named ent with the next 3 lines:
--> áéíóúñÑü¿?¡! <--
I execute the next script in IP
>>>for i in e.readlines():
... print i
--> ???????????! <--
I hope you see the problem produced. Some common letters in the spanish
language the ones with accent were replaced by another characters. May be
unicode is the cause.
To avoid this issue in C#, I use System.Text.Encoding.Default i.e.:
r=new StreamReader(@"C:\ent", System.Text.Encoding.Default);
w=new StreamWriter(@"C:\ent", False, System.Text.Encoding.Default);
Depending if I read and/or write data
How can I solve this in IP?
Charla con tus amigos en línea mediante MSN Messenger:
users mailing list
users at lists.ironpython.com
More information about the users