python中if语句的SyntaxError

时间:2014-10-13 15:33:19

标签: python python-2.7 if-statement

for ch in line:
    ch_good = u"%s" %ch
    if ord(ch_good) == 8212:
        ch_good = '-'
    elif ord(ch_good) == 8220 or ord(ch_good) == 8221:
        ch_good = '"'
    elif ord(ch_good) == 8230:
        ch_good = "..."
    elif ord(ch_good) == 8217:
        ch_good = "'"

    elif ord(ch_good) == 191 or ord(ch_good) == 187 or ord(ch_good) == 239:
        сh_good = ""

我在第24行确定了这个错误

    сh_good = ""
    ^
SyntaxError: invalid syntax    

我不知道自己做错了什么。

1 个答案:

答案 0 :(得分:3)

您的с不是ASCII c

>>> '''\
...         сh_good = ""
...         ^
... '''
'        \xd1\x81h_good = ""\n        ^\n'

U+0441 CYRILLIC SMALL LETTER ES\xd1\x81字节序列为UTF-8。

换句话说,你使用了一个西里尔字符,而在Python 2中则是一个错误。