擅长:python、mysql、java
<p><a href="http://rdflib.readthedocs.org/en/latest/apidocs/rdflib.html#rdflib.graph.Graph.serialize" rel="nofollow noreferrer">serialize method</a>接受作为文件路径的destination关键字。在您的示例中,您需要使用:</p>
<pre><code>g.serialize(destination='output.txt', format='turtle')
</code></pre>
<p>而不是</p>
<pre><code>file = open("output.txt", "w")
file.write(g.serialize(format='turtle'))
</code></pre>