By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

checking for ASCII character

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

Thanks

Daniel
Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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.