473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Locale case change not working

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

May 24 '07 #1
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
May 24 '07 #2
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

May 24 '07 #3

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

Similar topics

3
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...
3
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...
1
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...
6
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...
7
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...
2
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...
4
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:...
2
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...
3
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"
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.