473,287 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Re: How to covert ASCII to integer in Python?

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
2 1418
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Sebastian Krause | last post by:
Hello, I tried to read in some large ascii files (200MB-2GB) in Python using scipy.io.read_array, but it did not work as I expected. The whole idea was to find a fast Python routine to read in...
2
by: Albert Tu | last post by:
Hi, I am learning and pretty new to Python and I hope your guys can give me a quick start. I have an about 1G-byte binary file from a flat panel x-ray detector; I know at the beggining there...
13
by: Ray Z | last post by:
So far, I get the idea that if I want to use both the unmanaged and managed memory, I can not avoid memory copy. But I DO need to avoid it. I get a idea that maybe I could use "union" to convert...
12
by: IamIan | last post by:
I searched the archives but couldn't find anyone else with this problem. Basically I'm grabbing all ASCII files in a directory and doing geoprocessing on them. I need to calculate a z-factor based...
6
by: bruce | last post by:
hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii...
6
by: Calros Lo | last post by:
Dear all: I develop a programe that need when I get a string , such as "123" or "ABC",if I get string "123" and the system will help me to create new string "124" , if I get string "ABC" and the...
10
by: John | last post by:
Is there any built in function that converts ASCII to integer or vice versa in Python? Thanks!
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.