2013-09-27 75 views
3

我有以下的线,这是造成我的问题:Python if语句检查字符串中的英镑符号?

if "Total £" in studentfees:

回报:

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

我怎样才能解决这个问题?

预先感谢 - HYFLEX

回答

7

您可以添加以下文件:

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

另外:

if u"Total £" in studentfees: 
+1

谢谢,完美的作品。这个“你”做什么? – Ryflex

+1

它使它成为一个Unicode字符串:http://docs.python.org/2/howto/unicode.html –

+1

@Hyflex如果这回答你的问题,你应该接受它是正确的。 – That1Guy