472,110 Members | 2,260 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

checking for ASCII character

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

Thanks

Daniel
Jul 18 '05 #1
5 12364
Daniel wrote:
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

Jul 18 '05 #2
rm
Greg Krohn wrote:
Daniel wrote:
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


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

Jul 18 '05 #3
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):
ce******@jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
Jul 18 '05 #4
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
da***@dalkescientific.com
Jul 18 '05 #5
"Daniel" <da******@SPAMhalliwell1.plus.com> wrote in message news:<Qm******************@wards.force9.net>...
Hi, is there a way to check if a letter entered is an uppercase ASCII
character?


letter.isupper()
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by David Williams | last post: by
2 posts views Thread by Director - Minvent | last post: by
37 posts views Thread by chandy | last post: by
16 posts views Thread by akarui.tomodachi | last post: by
9 posts views Thread by simchajoy2000 | last post: by
6 posts views Thread by bruce | last post: by
6 posts views Thread by davetelling | last post: by
9 posts views Thread by =?Utf-8?B?UGhhbmlkaGFy?= | last post: by
reply views Thread by leo001 | last post: by

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.