Python string equality test delivers inconsistent results
<p>The following function is used in a script to create a static version of a Django site:</p>

<pre><code>def write_file(filename, content):
    filename = '{0}{1}.html'.format(BASEDIR, filename)
    if os.path.exists(filename):
        existing_file = io.open(filename, encoding='utf-8')
        existing_content = existing_file.read()
        existing_file.close()
        if existing_content != content:
            print "Content is not equal, writing file to {0}".format(filename)
            encoded_content = content.encode('utf-8')
            html_file = open(filename, 'w')
            html_file.write(encoded_content)
            html_file.close()
        else:
            print "Content is equal, nothing is written to {0}".format(filename)
</code></pre>

<p>When I run the script twice (without any changes to the database), one would expect no write operations at all. Strangely enough, more than half of the files are written over and over again.</p>
