Quantcast
Channel: Python 2.7 encoding and feedparser - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by agf for Python 2.7 encoding and feedparser

$
0
0

You're trying to compare encoded text to unicode. Python doesn't know the encoded text is UTF-8, so it guesses it's ASCII and tries to decode it to unicode for you. The solution is to decode it explicitly with the proper encoding.

Check out the Python Unicode HOWTO for more info.

I can reproduce your problem with this file:

# coding: utf-8word = "öäå"if u"ö" in word:    print True

And fix it with this file:

# coding: utf-8word = "öäå".decode('utf-8')if u"ö" in word:    print True

Viewing all articles
Browse latest Browse all 4

Trending Articles