用于检查包含非标准字符的字符串是否在另一个字符串内的if语句不起作用



假设我有以下代码:

a = 'naïve' # It contains the character ï
b = 'some text that may or may not contain the word we are looking for'
if a in b: #error happens here
    print 'success'

我想看看a是否在b内,但它显然不知道如何使用非英语标准的unicode字符。它给了我以下错误:

SyntaxError: Non-ASCII character 'xc3' in file app.py on line 10, but no encoding declared

我不知道该做什么或尝试。有线索吗?谢谢你。

将这一行放在文件的顶部:

# -*- coding: utf-8 -*-

相关内容

最新更新