Re: How to covert ASCII to integer in Python?
Mensanator <[EMAIL PROTECTED]> wrote: > On May 30, 10:03???am, Philipp Pagel <[EMAIL PROTECTED]> > wrote: > > 'P' is obviously not an ASCII representation of a number. > It is in base 36. Sure, but if that was the OP's intent he would most likely have mentioned it... As others have already guessed, it's most likely somethink like ord() he was after. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f. Genomorientierte Bioinformatik Technische Universität München http://mips.gsf.de/staff/pagel -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
On May 30, 7:59 pm, Mensanator <[EMAIL PROTECTED]> wrote: > On May 30, 6:44 pm, Joshua Kugler <[EMAIL PROTECTED]> 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. 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
On May 30, 6:44 pm, Joshua Kugler <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list
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/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 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
On May 30, 10:03�am, Philipp Pagel <[EMAIL PROTECTED]> wrote: > Skonieczny, Chris <[EMAIL PROTECTED]> 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 !!! > > 'P' is obviously not an ASCII representation of a number. It is in base 36. >>> a='P' >>> b=int(a,36) >>> b 25 > What did you expect? The closest number by visual appearance? > > cu > � � � � Philipp > > -- > Dr. Philipp Pagel > Lehrstuhl f. Genomorientierte Bioinformatik > Technische Universit�t M�nchenhttp://mips.gsf.de/staff/pagel -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
Skonieczny, Chris <[EMAIL PROTECTED]> 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 !!! 'P' is obviously not an ASCII representation of a number. What did you expect? The closest number by visual appearance? cu Philipp -- Dr. Philipp Pagel Lehrstuhl f. Genomorientierte Bioinformatik Technische Universität München http://mips.gsf.de/staff/pagel -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
In article <[EMAIL PROTECTED]>, "Skonieczny, Chris" <[EMAIL PROTECTED]> wrote: > YOU SHOULD REMOVE or CORRECT YOUR POST here: > http://mail.python.org/pipermail/python-list/2007-February/427841.html Why? There's nothing wrong there. > It is not true - eg. try : > a='P'# P is ASCII , isn't it ? > b=int(a) > and what you will get ? An error !!! You really don't see any difference between "convert '1' to an integer" and "convert 'P' to an integer"? In case there's actually a problem you're trying to solve here, try ord instead of int. > Or probably you yourself should - quote : > "You probably should go through the tutorial ASAP that is located here: > > http://docs.python.org/tut/ " > > - > [Image] -- David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
Some people spend many buck bying guessing games ... be nice ! hg -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
On Feb 23, 5:23 am, "John" <[EMAIL PROTECTED]> wrote: > 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" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > Is there any built in function that converts ASCII to integer or vice > versa > > in Python? > > > Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
On Feb 22, 6:35 pm, Lloyd Zusman <[EMAIL PROTECTED]> wrote: > "John" <[EMAIL PROTECTED]> writes: > > 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
"John" <[EMAIL PROTECTED]> writes: > I just found ord(c), which convert ascii to integer. > Anybody know what the reverse is? chr(i) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
John wrote: > I just found ord(c), which convert ascii to integer. > > Anybody know what the reverse is? > > "John" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
"John" <[EMAIL PROTECTED]> writes: > 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 [EMAIL PROTECTED] God bless you. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
I just found ord(c), which convert ascii to integer. Anybody know what the reverse is? "John" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is there any built in function that converts ASCII to integer or vice versa > in Python? > > Thanks! > > -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
Or perhaps... ord ("a") 97 chr (97) 'a' On 2/22/07, hg <[EMAIL PROTECTED]> wrote: 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' >>> -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
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' >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
On Feb 22, 5:43 pm, "John" <[EMAIL PROTECTED]> wrote: > 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) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to covert ASCII to integer in Python?
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 -- http://mail.python.org/mailman/listinfo/python-list