2013-09-27 111 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