both tow are unicode,but when compare,it doesn't workï¼
<pre><code># -*- coding: utf-8 -*- 
from bs4 import  BeautifulSoup 
import urllib2

response = urllib2.urlopen('http://bbs.szhome.com/80300-0-0-0-3005.html')
html = response.read()

soup = BeautifulSoup(html)

returntext = soup.find('dl',class_='fix').text 
print returntext

if isinstance(returntext,unicode):
    print 'ok1' #true,print ok1

text = u'ææ ç¸å³æ°æ®...'

if isinstance(text,unicode):
    print 'ok2' #true,print ok2

text2 = 'ææ ç¸å³æ°æ®...'
if isinstance(text2,str):
    print 'ok3' #true,print ok3

if returntext == text:
    print 'ok4' #both unicode,but not excute,why?
</code></pre>

<p>They aren't both unicode, they just look that way to you because your display decodes text2 for you. In fact, <code>isinstance(text2,str)</code> shows that text2 is clearly a string, not unicode. </p>

<p>Unicode was bolted onto python 2 and its usage is a little strange. <code>str</code> can hold any octet (typically ascii characters but binary binary data) and in your case its holding a utf-8 encoded version of the string. </p>

<p><code>text</code> is unicode and has 9 characters</p>

<pre><code>&gt;&gt;&gt; text = u'ææ ç¸å³æ°æ®...'
&gt;&gt;&gt; type(text), len(text)
(&lt;type 'unicode'&gt;, 9)
</code></pre>

<p><code>Text2</code> is a binary blob in a string, has 21 octets and is not the same as <code>text</code></p>

<pre><code>&gt;&gt;&gt; text2 = 'ææ ç¸å³æ°æ®...'
&gt;&gt;&gt; type(text2), len(text2)
(&lt;type 'str'&gt;, 21)
&gt;&gt;&gt; text == text2
__main__:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
False
</code></pre>

<p>But I can decode it into unicode and the comparison works</p>

<pre><code>&gt;&gt;&gt; text2_unicode = text2.decode('utf-8')
&gt;&gt;&gt; type(text2_unicode), len(text2_unicode)
(&lt;type 'unicode'&gt;, 9)
&gt;&gt;&gt; text == text2_unicode
True
</code></pre>

<p>This all works much better and much more clearly in python 3. You should not be using 2.x if you can avoid it.</p>

python unicode