问问题
12166 次
2 回答
13
Long dash is not an ASCII character. Declare encoding of your script, like this (somewhere on top):
#-*- coding: utf-8 -*-
There are also other encodings beside utf-8
but it is always safe to use utf-8
if not working with ASCII characters which covers virtually all (unicode) characters.
See PEP 0263 for more info.
于 2013-10-03T01:51:22.213 回答
1
I would like to link another answer: https://stackoverflow.com/a/42856932/3751268. However that only worked for Python 2.
Here is a solution for python 3:
my_str = '—asasas—'
my_str.replace(b'\xe2\x80\x94'.decode('utf-8'), '--')
于 2019-10-08T19:09:24.487 回答