Is there any built in function that converts ASCII to integer or vice versa
in Python?
Thanks! 10 53317
John wrote:
Is there any built in function that converts ASCII to integer or vice versa
in Python?
Thanks!
You probably should go through the tutorial ASAP that is located here: http://docs.python.org/tut/
Convert ascii string to integer:
a='1'
b=int(a)
Convert integer to ascii string:
a=1
b=str(a)
or
a=1
b="%i" % a
-Larry Bates
On Feb 22, 5:43 pm, "John" <rds1...@sh163.netwrote:
Is there any built in function that converts ASCII to integer or vice versa
in Python?
Thanks!
Try int.
ie.
try:
int_val = int(str_val)
except ValueError:
# conversion failed
Keir.
--
Keir Robinson
Sometimes a scream is better than a thesis. (Emerson)
John wrote:
Is there any built in function that converts ASCII to integer or vice
versa in Python?
Thanks!
>>int('10')
10
>>str(10)
'10'
>>>
I just found ord(c), which convert ascii to integer.
Anybody know what the reverse is?
"John" <rd*****@sh163.netwrote in message
news:er***********@netnews.upenn.edu...
Is there any built in function that converts ASCII to integer or vice
versa
in Python?
Thanks!
John wrote:
I just found ord(c), which convert ascii to integer.
Anybody know what the reverse is?
"John" <rd*****@sh163.netwrote in message
news:er***********@netnews.upenn.edu...
>Is there any built in function that converts ASCII to integer or vice
versa
>in Python?
Thanks!
The phrasing of your question threw us all. What you want is chr
backslash=chr(92)
-Larry Bates
"John" <rd*****@sh163.netwrites:
I just found ord(c), which convert ascii to integer.
Anybody know what the reverse is?
chr(i)
"John" <rd*****@sh163.netwrites:
I just found ord(c), which convert ascii to integer.
Anybody know what the reverse is?
The inverse of "ord" is "chr":
% python
Python 2.5 (r25:51908, Jan 5 2007, 00:12:45)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>ord('i')
105
>>chr(105)
'i'
>>>
IIRC, the first use of the names "ord" and "chr" for these functions
appeared in the Basic language in the 1960's ... in case anyone is
interested in this bit of historical trivia.
--
Lloyd Zusman lj*@asfast.com
God bless you.
On Feb 22, 6:35 pm, Lloyd Zusman <l...@asfast.comwrote:
"John" <rds1...@sh163.netwrites:
I just found ord(c), which convert ascii to integer.
Anybody know what the reverse is?
The inverse of "ord" is "chr":
% python
Python 2.5 (r25:51908, Jan 5 2007, 00:12:45)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>ord('i')
105
>>chr(105)
'i'
>>>
IIRC, the first use of the names "ord" and "chr" for these functions
appeared in the Basic language in the 1960's ... in case anyone is
interested in this bit of historical trivia.
In the versions of Basic that I've seen they were ASC (clearly ASCII)
and CHR$. I first saw ord in Pascal.
On Feb 23, 5:23 am, "John" <rds1...@sh163.netwrote:
I just found ord(c), which convert ascii to integer.
ord('\xff') -255
ord(unichr(666)) -666
What ascii?
What is stopping you from reading the documentation section on built-
in functions ( http://docs.python.org/lib/built-in-funcs.html)?
That way, you might find an answer to whatever your question really
is, without wasting time (yours and that of others trying to guess).
>
Anybody know what the reverse is?
"John" <rds1...@sh163.netwrote in message
news:er***********@netnews.upenn.edu...
Is there any built in function that converts ASCII to integer or vice
versa
in Python?
Thanks!
<yours and that of others trying to guess>
Some people spend many buck bying guessing games ... be nice !
hg This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lucas |
last post by:
hello one and all,
i am very new to java and i need to take an ascii character, say "A" or "a"
and convert it into its ascii integer code, say 65 or 97 respectively. then
i need to also go in...
|
by: Mark Dickinson |
last post by:
Here's a variant of André's brilliant idea that's
119 characters long, and fully printable:
j=''.join;seven_seg=lambda z:j(j(' _ | |_ _|_|'
)%u*2:]for a in z)
+"\n"for u in(3,7,8))
Mark
|
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...
|
by: micahc |
last post by:
I currently have a Python program that reads in emails from a POP3
server. As soon as the message is read in it is fed directly into a
PostgreSQL database for storage. Later, it is broken down...
|
by: ronrsr |
last post by:
I have an MySQL database called zingers. The structure is:
zid - integer, key, autoincrement
keyword - varchar
citation - text
quotation - text
I am having trouble storing text, as typed in...
|
by: Mantorok |
last post by:
Hi
Is it possible to convert 2 char values to an integer and be able to reverse
it?
I'm sure there must be some algorithm to achive this.
Any ideas?
Thanks
Kev
|
by: Steve Howell |
last post by:
The never-ending debate about PEP 3131 got me thinking
about natural languages with respect to Python, and I
have a bunch of mostly simple observations (some
factual, some anecdotal). I present...
|
by: Skonieczny, Chris |
last post by:
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 ? ...
|
by: Joshua Kugler |
last post by:
Skonieczny, Chris wrote:
int() converts a strings that is a valid intenter. What you're looking for
is ord().
In : ord('d')
Out: 100
In : a='P'
|
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...
|
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"....
|
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...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
| |