473,403 Members | 2,354 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,403 software developers and data experts.

diferent answers with isalpha()

Hi,

I have python with sys.version_info = (2, 4, 4, 'final', 0)

In Idle when I do print 'á'.isalpha() I get True. When I make and
execute a script file with the same code I get False.

Why do I have diferent answers ?
Thank you

Jul 13 '07 #1
3 2605
En Thu, 12 Jul 2007 21:05:42 -0300, <nu**@salgado.wsescribió:
Hi,

I have python with sys.version_info = (2, 4, 4, 'final', 0)

In Idle when I do print 'á'.isalpha() I get True. When I make and
execute a script file with the same code I get False.

Why do I have diferent answers ?
Do you include an encoding directive at the top? (If you omit it you get a
warning in 2.4 and an error in 2.5)

Try this:

import unicodedata
print unicodedata.name(u'á')

from IDLE and from inside a script. You should get "LATIN SMALL LETTER A
WITH ACUTE"; if not, Python thinks your terminal uses a different encoding
than the actual one.

--
Gabriel Genellina

Jul 13 '07 #2
On Jul 13, 5:05 am, n...@salgado.ws wrote:
In Idle when I do print 'á'.isalpha() I get True. When I make and
execute a script file with the same code I get False.

Why do I have diferent answers ?
Non-ASCII characters in ordinary (8-bit) strings have all kinds of
strangeness. First, the answer of isalpha() and friends depends on the
current locale. By default, Python uses the "C" locale where the
alphabetic characters are a-zA-z only. To set the locale to whatever
is the OS setting for the current user, put this near the beginning of
your script:

import locale
locale.setlocale(locale.LC_ALL,'')

Apparently IDLE does this for you. Hence the discrepancy you noted.

Second, there is the matter of encoding. String literals like the one
you used in your example are stored in whatever encoding your text
editor chose to store your program in. If it doesn't match the
encoding using by the current locale, once again the program fails.

As I see it, the only way to properly handle characters outside the
ASCII set is to use Unicode strings.

Jul 13 '07 #3
On Jul 13, 6:07 am, Jyotirmoy Bhattacharya <jmoy.mate...@gmail.com>
wrote:
On Jul 13, 5:05 am, n...@salgado.ws wrote:
In Idle when I do print 'á'.isalpha() I get True. When I make and
execute a script file with the same code I get False.
Why do I have diferent answers ?

Non-ASCII characters in ordinary (8-bit) strings have all kinds of
strangeness. First, the answer of isalpha() and friends depends on the
current locale. By default, Python uses the "C" locale where the
alphabetic characters are a-zA-z only. To set the locale to whatever
is the OS setting for the current user, put this near the beginning of
your script:

import locale
locale.setlocale(locale.LC_ALL,'')

Apparently IDLE does this for you. Hence the discrepancy you noted.

Second, there is the matter of encoding. String literals like the one
you used in your example are stored in whatever encoding your text
editor chose to store your program in. If it doesn't match the
encoding using by the current locale, once again the program fails.

As I see it, the only way to properly handle characters outside the
ASCII set is to use Unicode strings.
Jyotirmoy,

You are right. Thank you for your information.

I will follow your advice but it gets me into another problem with
string.maketrans/translate that I can't solve.

Jul 13 '07 #4

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

Similar topics

1
by: rrosa | last post by:
Hi there, I am trying to create a window that appears one label1="First Message" and after of 3,4 seconds I would like to append another label in the same window label2="Second Message" bellow of...
1
by: Bernardo | last post by:
Hi, Anyone knows how can I sellect a diferent cell or Row at runtime? Thanks a lot
23
by: Carlos | last post by:
Before in VB 6 I used to reference for examplea progressbar1 doin the following Form1.ProgressBar1.val =1 Now how do I refrence a control for a module if the control is in a different form ...
8
by: dananrg | last post by:
Seems like most web hosting providers support MySQL, but not PostgreSQL. I need a web hosting account that supports PostgreSQL for a particular personal project I'm working on (as well as Python,...
1
by: Marcelo Urbano Lima | last post by:
Hi I'm still learning python and I've been loving it, but, that's not the reason I'm writing. I'm trying to create an object only if a variable is alpha and see what I get. $ cat 1.py class...
0
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for...
3
by: Ivan | last post by:
Thanks to answer topic previous!!!! I use this script to update one table MERGE INTO EIS.CLI_HISTORY TXN USING EIS.CLI_MAPING CLI ON TXN.CLIENTID = CLI.CLIENTID WHEN MATCHED AND...
4
by: Pyenos | last post by:
#!/usr/bin/python #################################################### # answers.py --- A simple answer bot # Copyright (C) 2006 Logan Lee # # MESSAGE: # # This program is a simple...
12
by: colin | last post by:
Hi, Ive got a difference in results depending on wether I run my app in the debugger, or run it seperatly (or with <ctrl-f5>) the results in the debugger seem to be more correct, although the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.