LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python: converting a 3 character octal string into and ASCII char (https://www.linuxquestions.org/questions/programming-9/python-converting-a-3-character-octal-string-into-and-ascii-char-28429/)

llama_meme 08-21-2002 08:24 AM

python: converting a 3 character octal string into an ASCII char
 
OK, I'm trying to go through a string and replace all occurences of %xxx (where x is an octal digit) with the coresponding ASCII character.

Two problems:

I can't work out how to convert the string xxx into a number (string.atoi is for decimal numbers).

curses.ascii.unctrl(), which is supposed to convert a number into its corresponding character doesn't seem to work properly. For example, it treats 65 (decimal) as a control code, and returns some weird string that isn't 'A'. Documentation for it is at http://www.python.org/doc/current/li...ses.ascii.html

Alex

threebean 07-06-2010 02:00 PM

You can use string.atoi(s, base=8) for octal numbers.


All times are GMT -5. The time now is 11:37 PM.