“UnicodeEncodeError: 'ascii' codec can't encode character”

前端 未结 4 1838
星月不相逢
星月不相逢 2020-12-02 19:01

I\'m trying to pass big strings of random html through regular expressions and my Python 2.6 script is choking on this:

UnicodeEncodeError: \'ascii\' codec can\'t e

4条回答
  •  温柔的废话
    2020-12-02 19:40

    The "best" way always depends on your requirements; so, what are yours? Is ignoring non-ASCII appropriate? Should you replace ™ with "(tm)"? (Which looks fancy for this example, but quickly breaks down for other codepoints—but it may be just what you want.) Could the exception be exactly what you need; now you just need to handle it in some way?

    Only you can really answer this question.

提交回复
热议问题