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

Re: How to covert ASCII to integer in Python?

P: n/a
Skonieczny, Chris wrote:
YOU SHOULD REMOVE or CORRECT YOUR POST here:
http://mail.python.org/pipermail/pyt...ry/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

Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 30, 6:44*pm, Joshua Kugler <jkug...@bigfoot.comwrote:
Skonieczny, Chris wrote:
YOU SHOULD REMOVE or CORRECT YOUR POST here:
http://mail.python.org/pipermail/pyt...ry/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
Jun 27 '08 #2

P: n/a
On May 30, 7:59*pm, Mensanator <mensana...@aol.comwrote:
On May 30, 6:44*pm, Joshua Kugler <jkug...@bigfoot.comwrote:


Skonieczny, Chris wrote:
YOU SHOULD REMOVE or CORRECT YOUR POST here:
>http://mail.python.org/pipermail/pyt...ry/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.
Oops! I meant ord(a)-64, of course.
>

In [1]: ord('d')
Out[1]: 100
In [2]: a='P'
In [3]: b=ord(a)
In [4]: b
Out[4]: 80
j
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.