Printing single quote become weird character in .txt-file

33
February 03, 2019, at 4:40 PM

I used Selenium to scrape some sentences, and then print the result to a .txt-file, but it cannot display ' but instead some weird character:

Original sentence:

I don't think so.

in .txt file:

I don? think so.

I have specified the .txt encoding to "utf-8" already, what should I do?

Answer 1

You need to open the file for writing in "utf-8" for that:

with open("file.txt", "w", encoding="utf-8") as file
    file.write("your_text")

Hope it helps you!

Answer 2

try to add a backslash \: I don\'t think so. Backslash is the escape character in python. https://www.quackit.com/python/reference/python_3_escape_sequences.cfm

READ ALSO
remove an animation iteration event listener to animated child node

remove an animation iteration event listener to animated child node

SCENARIO: I have a top/parent <div> that has an infinite CSS animation on itIt also has some <div> as sub/child nodes and some (one or more) might have as well an infinite CSS animation on them

42
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout

android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout

I experienced this error while working on an android food ordering app in android studio 33:

32
data is not inserted correctly in csv

data is not inserted correctly in csv

When i add data into csv programmatically it gives me below issue:

32