encoding

Python str vs unicode on Windows, Python 2.7, why does 'á' become 'xa0'

Python str vs unicode on Windows, Python 2.7, why does 'á' become 'xa0' Question: Background I’m using a Windows machine. I know Python 2.* is not supported anymore, but I’m still learning Python 2.7.16. I also have Python 3.7.1. I know in Python 3.* "unicode was renamed to str" I use Git Bash as my …

Total answers: 1

File. exe in win cannot identify the file encoding, the file seems to be corrupted, what can be done?

File. exe in win cannot identify the file encoding, the file seems to be corrupted, what can be done? Question: For some files, python’s chardet library of chardet.detect(f.read())[‘encoding’] returns None. path=r"C:A chinese novel.TXT" with codecs.open(path, ‘rb’) as f: encoding=chardet.detect(f.read()) print(encoding) # RETURN {‘encoding’: None, ‘confidence’: 0.0, ‘language’: None} I’ll use os.popen("file -bi "%s" | gawk …

Total answers: 1

subprocess stdout without colors

subprocess stdout without colors Question: I am running a command line tool that returns a coloured output (similar to ls –color). I run this tool via subprocess: process = subprocess.run([‘ls –color’], shell=True, stdout=subprocess.PIPE) process.stdout.decode() But the result is, of course, with the color instructions like x1b[mx1b[m which makes further processing of the output impossible. How …

Total answers: 2

In python, how would one change the string 'Nelson Velxc3xa1zquez' to 'Nelson Velazquez'?

In python, how would one change the string 'Nelson Vel\xc3\xa1zquez' to 'Nelson Velazquez'? Question: The issue is with proper encoding. The data type is a string, where the string does not convert the spanish á properly and instead shows as xc3xa1. How do you convert these to show ‘Nelson Velazquez’? example variable: text = ‘Nelson …

Total answers: 2

Writing in same row in Gujarati in python using CSV writer

Writing in same row in Gujarati in python using CSV writer Question: My code: import csv # Create a list of Gujarati strings strings = [[‘હેલો, વર્લ્ડ!’, ‘સુપ્રભાત’, ‘મારા નામ હેઠળ છે’]] # Open the CSV file in ‘w’ mode with open(‘Gujarati.csv’, ‘w’, encoding=’utf-16′,newline=”) as f: # Create a CSV writer writer = csv.writer(f) # …

Total answers: 1

Python utf-8 encoding not following unicode rules

Python utf-8 encoding not following unicode rules Question: Background: I’ve got a byte file that is encoded using unicode. However, I can’t figure out the right method to get Python to decode it to a string. Sometimes is uses 1-byte ASCII text. The majority of the time it uses 2-byte "plain latin" text, but it …

Total answers: 1

Python's psycopg2 & logging: Logged at the DEBUG-level queries are recorded in bytes

Python's psycopg2 & logging: Logged at the DEBUG-level queries are recorded in bytes Question: I have connection to PostgreSQL database: LOGGER = Logger().LOGGER # … self.connection = psycopg2.connect(connection_factory=LoggingConnection, dbname=…, user=…, password=…, host=…, options="-c search_path=…") self.connection.initialize(LOGGER) self.cursor = self.connection.cursor() It’s Logger class: # some data _MODE = "w" _ENCODING = "utf-8" _FORMATTER = "%(asctime)s %(levelname)s [%(filename)s:%(lineno)s] …

Total answers: 2

Error Initalizing Stable diffusion with python 3.10.6. 'str' object has no attribute 'isascii'

Error Initalizing Stable diffusion with python 3.10.6. 'str' object has no attribute 'isascii' Question: I’m trying to set Up Stable Diffusion 1.5 from GIT https://github.com/AUTOMATIC1111/stable-diffusion-webui. I’ve followed a tutorial https://www.youtube.com/watch?v=ycQJDJ-qNI8&t=0s. To avoid problems with multiple python versions I’ve removed older Python version and installed only Python 3.10.6, then only 3.10.9, but I receive the same …

Total answers: 1

Storing several location values from list into another list in python

Storing several location values from list into another list in python Question: I’m trying to get the location of all the letters of an input "text" from a list "alphabet". <- Thats the part I’m having trouble with. For some context: after those letters are stored, the list aplphabet will shift a given number of …

Total answers: 2