擅长:python、mysql、java
<p>我自己已经发现,对于像这样的非标准类的实例,<code>scandir.DirEntry</code>,最好的方法是<strong>将类成员数据转换成标准对象的组合(可能是嵌套的),比如(<code>list</code>,<code>dict</code>,等等)。在</p>
<p>例如,在<code>scandir.DirEntry</code>的特定情况下,可以按如下方式进行。在</p>
<pre><code>import scandir, pickle
s = scandir.scandir("D:\\PYTHON")
entry = s.next()
# first convert the stat object to st_
st = entry.stat()
st_ = {'st_mode':st.st_mode, 'st_size':st.st_size,\
'st_atime':st.st_atime, 'st_mtime':st.st_mtime,\
'st_ctime':st.st_ctime}
# now convert the entry object to entry_
entry_ = {'name':entry.name, 'is_dir':entry.is_dir(), \
'path':entry.path, 'stat':st_}
# one may need some other class member data also as necessary
# now pickle the converted entry_
data = pickle.dumps(entry_)
</code></pre>
<p>尽管出于我的目的,我只需要数据,但在另一端取消拾取之后,可能需要<strong>将未拾取的<code>entry_</code>重构为未拾取的<code>scandir.DirEntry</code>对象“entry”。<strong>但是,我还没有弄清楚如何重构类实例,以及如何为诸如</strong><code>is_dir()</code>,<code>stat()</code>等方法的行为设置数据。在</p>