[Tutor] String to integer?

Blake Winton bwinton at latte.ca
Wed Sep 1 15:27:12 CEST 2004


adam wrote:
> What's the easiest way of creating an integer which is based on a value of
> a letter? I really don't mind if it was based on the ascii code, or
> another equivalent.

 >>> ord('a')
97
 >>> chr(97)
'a'
 >>> ord('ab')
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: ord() expected a character, but string of length 2 found

(Putting on my user-hat for a second, you _really_ want 26 buttons on a 
single form?!?  That's probably going to be confusing to look at.  Is 
there another way you could get the user's input?)

Later,
Blake.


More information about the Tutor mailing list