encoding

Python encoding textfile, open it, replace multiple sections and output without empty lines as text formatted in .csv style

Python encoding textfile, open it, replace multiple sections and output without empty lines as text formatted in .csv style Question: What I have is a file "test.xls" which is basically a old xls (xml formatting) which looks like this in notepad: <table cellspacing="1" rules="all" border="1"> <tr> <td>Row A</td><td>Row B</td><td>Row C</td> </tr> <tr> <td>New York</td><td>23</td><td>warm</td> </tr> …

Total answers: 1

How to decode escaped Unicode characters?

How to decode escaped Unicode characters? Question: I’m trying to replace escaped Unicode characters with the actual characters: string = "\u00c3\u00a4" print(string.encode().decode("unicode-escape")) The expected output is ä, the actual output is ä. Asked By: Toast || Source Answers: The following solution seems to work in similar situations (see for example this case about decoding broken …

Total answers: 3

How do I get the face_recognition encoding from many images in a directory and store them in a CSV File?

How do I get the face_recognition encoding from many images in a directory and store them in a CSV File? Question: This is the code I have and it works for single images: Loading images and apply the encoding from face_recognition.face_recognition_cli import image_files_in_folder Image1 = face_recognition.load_image_file(“Folder/Image1.jpg”) Image_encoding1 = face_recognition.face_encodings(Image1) Image2 = face_recognition.load_image_file(“Folder/Image2.jpg”) Image_encoding2 = face_recognition.face_encodings(Image2) …

Total answers: 1

Convert octal representation of UTF-8

Convert octal representation of UTF-8 Question: I have a variable like this: >>> s = ‘\320\227\320\264\320\260\320\275\320\270\320\265 \320\261\321\213\320\262\321\210\320\265\320\271’ >>> print(s) 320227320264320260320275320270320265 320261321213320262321210320265320271 This contains the octal escape representations of the UTF-8 encoding of the string “Зданиебывшей” (octal 320 227 = hex D0 97 = UTF-8 for “З”). How can I decode this string to “Зданиебывшей”? Asked …

Total answers: 1

'utf-8' codec can't decode byte 0xa0 in position 4276: invalid start byte

'utf-8' codec can't decode byte 0xa0 in position 4276: invalid start byte Question: I try to read and print the following file: txt.tsv (https://www.sec.gov/files/dera/data/financial-statement-and-notes-data-sets/2017q3_notes.zip) According to the SEC the data set is provided in a single encoding, as follows: Tab Delimited Value (.txt): utf-8, tab-delimited, n- terminated lines, with the first line containing the field …

Total answers: 7

UTF-8 to ISO-8859-1 encoding: replace special characters with closest equivalent

UTF-8 to ISO-8859-1 encoding: replace special characters with closest equivalent Question: Does anyone know of Python libraries that allows you to convert a UTF-8 string to ISO-8859-1 encoding in a smart way? By smart, I mean replacing characters like “–” by “-” or so. And for the many characters for which an equivalent really cannot …

Total answers: 4

Unicode Decoding error when trying to generate pdf with non-ascii characters

Unicode Decoding error when trying to generate pdf with non-ascii characters Question: I am working with some software that is generating an error when trying to create a pdf from html that contains non-ascii characters. I have created a much simpler program to reproduce the problem and help me understand what is going on. #!/usr/bin/python …

Total answers: 3

Why does base64.b64encode() return a bytes object?

Why does base64.b64encode() return a bytes object? Question: The purpose of base64.b64encode() is to convert binary data into ASCII-safe “text”. However, the method returns an object of type bytes: >>> import base64 >>> base64.b64encode(b’abc’) b’YWJj’ It’s easy to simply take that output and decode() it, but my question is: what is a significance of base64.b64encode() …

Total answers: 2

convert ansi escape to utf-8 in python

convert ansi escape to utf-8 in python Question: I may be wrong in accessing weather this string is ansi or anything else but it comes from rtf docs with heading. {rtf1ansiansicpg1252 the string of interest from doc is: ansi_string = r’3 u176? u177? 0.2u176? (2u952?)’ when i open the doc with word it gives me …

Total answers: 1

Python – Auto Detect Email Content Encoding

Python – Auto Detect Email Content Encoding Question: I am writing a script to process emails, and I have access to the raw string content of the emails. I am currently looking for the string “Content-Transfer-Encoding:” and scanning the characters that follow immediately after, to determine the encoding. Example encodings: base64 or 7bit or quoted-printable …

Total answers: 3