Dumb noob q: ASCII value of a character
John Hazen
invalid at hazen.net
Thu Feb 26 14:48:56 EST 2004
* Steve Horsley <shoot at the.moon> [2004-02-26 11:28]:
> How can I get the ASCII value of a character, e.g. I have:
>
> str = "A B"
> for index in range(0, len(str)):
> value = WHAT_GOES_HERE?(str[index])
> print value
>
>
> and I hope to get:
> 65
> 32
> 66
ord.
(And yes, it's a little hard to find. The first time I had to
solve this problem, I used:
>>> import string
>>> string.index(string._idmap,'A')
65
)
Also of note: Strings can be used as iterators, so there's no need to
use that indexing trick:
>>> str = "A B"
>>> for char in str:
... print ord(char)
...
65
32
66
>>>
-John
< my_first_name AT my_last_name DOT net >
More information about the Python-list
mailing list