擅长:python、mysql、java
<p>Python3:</p>
<pre><code>from io import StringIO
...
with open('file.xml', mode='w') as f:
print(buf.getvalue(), file=f)
</code></pre>
<p>Python2.x:</p>
<pre><code>from StringIO import StringIO
...
with open('file.xml', mode='w') as f:
f.write(buf.getvalue())
</code></pre>