Re: How to covert ASCII to integer in Python?



On May 30, 6:44 pm, Joshua Kugler <jkug...@xxxxxxxxxxx> wrote:
Skonieczny, Chris wrote:
YOU SHOULD REMOVE or CORRECT YOUR POST here:
http://mail.python.org/pipermail/python-list/2007-February/427841.html

It is not true - eg. try :
a='P'            # P is ASCII , isn't it ?
b=int(a)
and what you will get ? An error !!!

Or probably you yourself should - quote :
"You probably should go through the tutorial ASAP that is located here:

http://docs.python.org/tut/";

int() converts a strings that is a valid intenter.  What you're looking for
is ord().

Possibly. Perhaps the OP wants the position of 'P'
in the alphabet, in which case he wants b=64-ord(a)
or b=16.


In [1]: ord('d')
Out[1]: 100

In [2]: a='P'

In [3]: b=ord(a)

In [4]: b
Out[4]: 80

j

.



Relevant Pages

  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... where Bstrlib fails to be able to deal with them due to its design ... If the DOS port hadn't been dropped then depending on the compiler we ...
    (comp.lang.c)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... If the DOS port hadn't been dropped then depending on the compiler we ... And how do you deal with the fact that the language limits your sizes ...
    (comp.lang.c)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... Handling an RTF document that you will be writing to a variable length ... the scalar fields. ...
    (comp.lang.c)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... I do have good reason for doing this. ... If the DOS port hadn't been dropped then depending on the compiler we ...
    (comp.lang.c)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... Handling an RTF document that you will be writing to a variable length ... the scalar fields. ...
    (comp.lang.c)