How to covert ASCII to integer in Python?

Joshua Kugler jkugler at bigfoot.com
Fri May 30 19:44:38 EDT 2008


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().

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

In [2]: a='P'

In [3]: b=ord(a)

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

j




More information about the Python-list mailing list