When using unicode the case change works:
>>print u'É'.lower()
é
But when using the pt_BR.utf-8 locale it doesn't:
>>locale.setlocale(locale.LC_ALL, 'pt_BR.utf-8')
'pt_BR.utf-8'
>>locale.getlocale()
('pt_BR', 'utf')
>>print 'É'.lower()
É
What am I missing? I'm in Fedora Core 5 and Python 2.4.3.
# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
Regards, Clodoaldo Pinto Neto 2 2212
Clodoaldo wrote:
When using unicode the case change works:
>>>print u'É'.lower()
é
But when using the pt_BR.utf-8 locale it doesn't:
>>>locale.setlocale(locale.LC_ALL, 'pt_BR.utf-8')
'pt_BR.utf-8'
>>>locale.getlocale()
('pt_BR', 'utf')
>>>print 'É'.lower()
É
What am I missing? I'm in Fedora Core 5 and Python 2.4.3.
# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
Regards, Clodoaldo Pinto Neto
str.lower() operates on bytes and therefore doesn't handle encodings with
multibyte characters (like utf-8) properly:
>>u"É".encode("utf8")
'\xc3\x89'
>>u"É".encode("latin1")
'\xc9'
>>import locale locale.setlocale(locale.LC_ALL, "de_DE.utf8")
'de_DE.utf8'
>>print unicode("\xc3\x89".lower(), "utf8")
É
>>locale.setlocale(locale.LC_ALL, "de_DE.latin1")
'de_DE.latin1'
>>print unicode("\xc9".lower(), "latin1")
é
I recommend that you forget about byte strings and use unicode throughout.
Peter
On May 24, 6:40 am, Peter Otten <__pete...@web.dewrote:
Clodoaldo wrote:
When using unicode the case change works:
>>print u'É'.lower()
é
But when using the pt_BR.utf-8 locale it doesn't:
>>locale.setlocale(locale.LC_ALL, 'pt_BR.utf-8')
'pt_BR.utf-8'
>>locale.getlocale()
('pt_BR', 'utf')
>>print 'É'.lower()
É
What am I missing? I'm in Fedora Core 5 and Python 2.4.3.
# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
Regards, Clodoaldo Pinto Neto
str.lower() operates on bytes and therefore doesn't handle encodings with
multibyte characters (like utf-8) properly:
>u"É".encode("utf8")
'\xc3\x89'
>u"É".encode("latin1")
'\xc9'
>import locale locale.setlocale(locale.LC_ALL, "de_DE.utf8")
'de_DE.utf8'
>print unicode("\xc3\x89".lower(), "utf8")
É
>locale.setlocale(locale.LC_ALL, "de_DE.latin1")
'de_DE.latin1'
>print unicode("\xc9".lower(), "latin1")
é
I recommend that you forget about byte strings and use unicode throughout.
Now I understand it. Thanks.
Regards, Clodoaldo Pinto Neto This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Adrian Parker |
last post by:
I have a server app which is sent a date in the local format of the client
machine. I've no control over the client app at all, so have to code at the
server end to cope with any problems. The...
|
by: Ksenia Marasanova |
last post by:
Hi,
I have some problems with locale module.
On my workstation, changing locale doesn't have effect:
Python 2.3 (#1, Sep 13 2003, 00:49:11)
on darwin
Type "help", "copyright", "credits" or...
|
by: Cagdas Ozgenc |
last post by:
Greetings.
I am confused about C++ standard library locale stuff. It seems as if the
implementations of locales are not part of the library, but only some
guideline classes are there.
What is...
|
by: Troels Arvin |
last post by:
Hello,
In the init-script contained in the RPMs downloadable from the PostgreSQL
site (I checked the one for Fedora), an explicit locale is set before
running initdb. - And the explicit locale...
|
by: Peter Jansson |
last post by:
Dear group,
I have been struggling to get a simple program for inserting and
extracting std::tm objects to/from streams to work. The code below tries
to read a std::tm object from a...
|
by: cris |
last post by:
Hi,
I got trouble when I try to change the locale used in a program foo.cc
// ----------------- begin
#include <iostream>
#include <locale>
#include <exception>
using namespace std;
int...
|
by: Matt F |
last post by:
I have an application that utilizes a dataset. I've found just today, that
if the regional language settings are changed at the point of where I
instantiate the DataSet an error is thrown of:...
|
by: Daniele C. |
last post by:
I will report a snippet from http://php.net/setlocale
I spent about 2 seconds before thinking: can it really be? I mean, is
there no way to set locale info per thread? And after a brief web...
|
by: Mario Ruggier |
last post by:
Hi,
i had the following problem when installing py3.0rc1 on a Mac OS X
10.5.5. On this system, the default locale values are:
$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |