ascii

Python: replace french letters with english

Python: replace french letters with english Question: I would like to replace all the french letters within words with their ASCII equivalent. letters = [[‘é’, ‘à’], [‘è’, ‘ù’], [‘â’, ‘ê’], [‘î’, ‘ô’], [‘û’, ‘ç’]] for x in letters: for a in x: a = a.replace(‘é’, ‘e’) a = a.replace(‘à’, ‘a’) a = a.replace(‘è’, ‘e’) a …

Total answers: 5

Detect whether a Python string is a number or a letter

Detect whether a Python string is a number or a letter Question: How can I detect either numbers or letters in a string? I am aware you use the ASCII codes, but what functions take advantage of them? Asked By: TriskelionKal || Source Answers: Check if string is nonnegative digit (integer) and alphabet You may …

Total answers: 2

How to detect non-ASCII character in Python?

How to detect non-ASCII character in Python? Question: I’m parsing multiple XML files with Python 2.7, there are some strings like: string =”[2,3,13,37–41,43,44,46]”. I split them to get a list of all elements, and then I have to detect elements with “–” like “37–41”, but it turns out this is not a regular dash, it’s …

Total answers: 6

UnicodeEncodeError: 'ascii' codec can't encode character at special name

UnicodeEncodeError: 'ascii' codec can't encode character at special name Question: My python (ver 2.7) script is running well to get some company name from local html files but when it comes to some specific country name, it gives this error “UnicodeEncodeError: ‘ascii’ codec can’t encode character” Specially getting error when this company name comes Company …

Total answers: 2

Print full ascii art

Print full ascii art Question: I am trying to print ascii art like this: print((“”” ._ o o _`-)|_ ,”” ,” ## | ಠ ಠ. ,” ## ,-__ `. ,” / `–._;) ,” ## / ,” ## / “””).encode(‘utf-8’)) And the output does not look right at all. What is the proper method of printing …

Total answers: 7

Finding the Values of the Arrow Keys in Python: Why are they triples?

Finding the Values of the Arrow Keys in Python: Why are they triples? Question: I am trying to find the values that my local system assigns to the arrow keys, specifically in Python. I am using the following script to do this: import sys,tty,termios class _Getch: def __call__(self): fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: …

Total answers: 3

Replace non-ASCII characters with a single space

Replace non-ASCII characters with a single space Question: I need to replace all non-ASCII (x00-x7F) characters with a space. I’m surprised that this is not dead-easy in Python, unless I’m missing something. The following function simply removes all non-ASCII characters: def remove_non_ascii_1(text): return ”.join(i for i in text if ord(i)<128) And this one replaces non-ASCII …

Total answers: 12

Convert an int value to unicode

Convert an int value to unicode Question: I am using pyserial and need to send some values less than 255. If I send the int itself the the ascii value of the int gets sent. So now I am converting the int into a unicode value and sending it through the serial port. unichr(numlessthan255); However …

Total answers: 4

Converting all chars in a string to ascii hex in python

Converting all chars in a string to ascii hex in python Question: Just looking for python code that can turn all chars from a normal string(all english alphbetic letters) to ascii hex in python. I’m not sure if I’m asking this in the wrong way because i’ve been searching for this but can’t seem to …

Total answers: 5

How to print UTF-8 encoded text to the console in Python < 3?

How to print UTF-8 encoded text to the console in Python < 3? Question: I’m running a recent Linux system where all my locales are UTF-8: LANG=de_DE.UTF-8 LANGUAGE= LC_CTYPE=”de_DE.UTF-8″ LC_NUMERIC=”de_DE.UTF-8″ LC_TIME=”de_DE.UTF-8″ … LC_IDENTIFICATION=”de_DE.UTF-8″ LC_ALL= Now I want to write UTF-8 encoded content to the console. Right now Python uses UTF-8 for the FS encoding but …

Total answers: 5