En dash/ Em dash breaking txt file formatting when trying to read in cmd

Viewed 177

I'm trying to manipulate a txt file that uses en dashes, but cmd reads it as –. Em dashes also have a broken formatting and are displayed as — The funny thing is that if I use both symbols inside the script (.py file) and associate it to a print command, all is displayed correctly. In interpreter also no problem at all. Is there any way I can make it recognize those characters before importing the file? Thank you!

1 Answers

I no longer need help with this since I has able to figure out on my own, but I'm keeping it here since it might help others in the future.

The problem was that py was opening the file as ANSI, while due to the special characters the file had to be opened as UTF-8. So by adding encoding='utf-8' when calling the open function solved the problem.

Related