擅长:python、mysql、java
<p>您可以使用<a href="http://docs.python.org/library/pickle.html#what-can-be-pickled-and-unpickled" rel="noreferrer">pickle.dumps</a>,它的返回可拾取对象作为字符串,您不需要将其写入临时文件。</p>
<blockquote>
<p>Return the pickled representation of
the object as a <strong>string</strong>, instead of
writing it to a file.</p>
</blockquote>
<pre><code>import pickle
class Foo:
attr = 'a class attr'
picklestring = pickle.dumps(Foo)
</code></pre>