Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scandir, pickle
- s = scandir.scandir("D:\PYTHON")
- entry = s.next()
- data = pickle.dumps(entry)
- File "untitled.py", line 5, in <module>
- data = pickle.dumps(item)
- File "C:Python27Libpickle.py", line 1374, in dumps
- Pickler(file, protocol).dump(obj)
- File "C:Python27Libpickle.py", line 224, in dump
- self.save(obj)
- File "C:Python27Libpickle.py", line 306, in save
- rv = reduce(self.proto)
- File "C:Python27Libcopy_reg.py", line 70, in _reduce_ex
- raise TypeError, "can't pickle %s objects" % base.__name__
- TypeError: can't pickle DirEntry objects
- 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 members also as necessary
- # now pickle the converted entry_
- data = pickle.dumps(entry_)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement