checking for ASCII character

D

Daniel

Hi, is there a way to check if a letter entered is an uppercase ASCII
character?

Thanks

Daniel
 
G

Greg Krohn

Daniel said:
Hi, is there a way to check if a letter entered is an uppercase ASCII
character?

Thanks

Daniel

If you just want to know if a character is uppercase:

if character.isupper():
<some code>

If it needs to be ASCII, the simplest way is probably:

if ord(character) in range(65, 91):
<some code>



greg
 
A

Andrei

Daniel wrote on Thu, 13 Nov 2003 19:59:12 -0000:
Hi, is there a way to check if a letter entered is an uppercase ASCII
character?

ascii_uppercase in the string module contains all uppercase ASCII chars.
Use "if ... in ..." to find out whether your letter is in that constant.

--
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
(e-mail address removed). Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
 
R

rm

Greg said:
If you just want to know if a character is uppercase:

if character.isupper():
<some code>

If it needs to be ASCII, the simplest way is probably:

if ord(character) in range(65, 91):
<some code>



greg

one could check for ascii by doing:

try :
character.encode('ascii')
except UnicodeDecodeError :
ascii = False
else :
ascii = True

if ascii and character.isupper() :
pass

or something like it

bye,
rm
 
A

Andrew Dalke

Greg Krohn:
If it needs to be ASCII, the simplest way is probably:

if ord(character) in range(65, 91):
<some code>

or

if character in string.ascii_uppercase:
...

Andrew
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top