【问题标题】:Python if statement checking for a £ pound sign in a string?Python if 语句检查字符串中的英镑符号?
【发布时间】:2013-10-03 21:39:15
【问题描述】:

我有以下导致我出现问题的行:

if "Total £" in studentfees:

返回:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 4: ordinal not in range(128)

我该如何解决这个问题?

提前致谢 - 海福克斯

【问题讨论】:

    标签: python python-2.7 if-statement unicode


    【解决方案1】:

    您可以在文件中添加以下内容:

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

    还有:

    if u"Total £" in studentfees:
    

    【讨论】:

    • @Hyflex 如果这回答了你的问题,你应该接受它是正确的。
    • 正是我所需要的,你是国王和绅士
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-02
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    相关资源
    最近更新 更多