character-encoding

Generating and reading QR codes with special characters

Generating and reading QR codes with special characters Question: I’m writing Python program that does the following: Create a QR code > Save to a png file > Open the file > Read the QR code information However, when the data on the code has special characters, I got some confusion output data. Here’s my …

Total answers: 2

How to read Turkish chars from txt file in Python?

How to read Turkish chars from txt file in Python? Question: I am trying to read user credentials from the text file. In the password, there is ‘ü’ character. When I read from txt. It prints ‘l’ character. UTF8 does not work for Turkish characters. How can I read? def get_username_password(): dosya = open("D:\user.txt","r",encoding="utf8",errors=’ignore’) line …

Total answers: 2

Python 3 : Converting UTF-8 unicode Hindi Literal to Unicode

Python 3 : Converting UTF-8 unicode Hindi Literal to Unicode Question: I have a string of UTF-8 literals ‘xe0xa4xb9xe0xa5x80 xe0xa4xacxe0xa5x8bxe0xa4xb2’ which covnverts to ही बोल in Hindi. I am unable convert string a to bytes a = ‘xe0xa4xb9xe0xa5x80 xe0xa4xacxe0xa5x8bxe0xa4xb2′ #convert a to bytes #also tried a = bytes(a,’utf-8’) a = a.encode(‘utf-8′) s = str(a,’utf-8’) The …

Total answers: 3

Python googletrans encoding weird chars

Python googletrans encoding weird chars Question: I have an ui which takes german language among other things and translate these in english sentences. # -*- coding: utf-8 -*- from googletrans import Translator def tr(s) translator = Translator() return translator.translate(wordDE,src=’de’,dest=’en’).text Sometimes I get weird characters from the translator. For example: DE: Pascal und PHP sind Programmiersprachen …

Total answers: 1

Python : Can't read '' as a string

Python : Can't read '\' as a string Question: I wanted to replace a string : ‘li\oa’ by ‘ext’ but I get this error error: octal escape value 505 outside of range 0-0o377 I know that the problem is: string containing these chracters ‘\’, so the question is : How can i read these backslashes …

Total answers: 2

How to deal with strings containing character codes?

How to deal with strings containing character codes? Question: 201 is a character code recognised in Python. What is the best way to ignore this in strings? s = ‘2016’ s = s.replace(‘\’, ‘/’) print s #6 Asked By: John Crow || Source Answers: If you have a string literal with a backslash in it, …

Total answers: 1

Convert bytes data inside a string to a true bytes object

Convert bytes data inside a string to a true bytes object Question: In Python 3, I have a string like the following: mystr = “x00x00x01x01x80x02xc0x02x00” This string was read from a file and it is the bytes representation of some text. To be clear, this is a unicode string, not a bytes object. I need …

Total answers: 1

UnicodeEncodeError when reading a file

UnicodeEncodeError when reading a file Question: I am trying to read from rockyou wordlist and write all words that are >= 8 chars to a new file. Here is the code – def main(): with open(“rockyou.txt”, encoding=”utf8″) as in_file, open(‘rockout.txt’, ‘w’) as out_file: for line in in_file: if len(line.rstrip()) < 8: continue print(line, file = …

Total answers: 3

Remove non-ASCII characters from pandas column

Remove non-ASCII characters from pandas column Question: I have been trying to work on this issue for a while.I am trying to remove non ASCII characters form DB_user column and trying to replace them with spaces. But I keep getting some errors. This is how my data frame looks: +———————————————————– | DB_user source count | …

Total answers: 8