擅长:python、mysql、java
<p>下面是一个已完成的示例,请阅读注释:</p>
<pre><code>#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# The above encoding declaration is required and the file must be saved as UTF-8
from __future__ import with_statement # Not required in Python 2.6 any more
import codecs
p = u"абвгдежзийкл" # note the 'u' prefix
print p # probably won't work on Windows due to a complex issue
with codecs.open("tets.txt", "w", "utf-16") as stream: # or utf-8
stream.write(p + u"\n")
# Now you should have a file called "tets.txt" that can be opened with Notepad or any other editor
</code></pre>