Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import scandir, pickle
  2.  
  3. s = scandir.scandir("D:\PYTHON")
  4. entry = s.next()
  5. data = pickle.dumps(entry)
  6.  
  7. File "untitled.py", line 5, in <module>
  8. data = pickle.dumps(item)
  9. File "C:Python27Libpickle.py", line 1374, in dumps
  10. Pickler(file, protocol).dump(obj)
  11. File "C:Python27Libpickle.py", line 224, in dump
  12. self.save(obj)
  13. File "C:Python27Libpickle.py", line 306, in save
  14. rv = reduce(self.proto)
  15. File "C:Python27Libcopy_reg.py", line 70, in _reduce_ex
  16. raise TypeError, "can't pickle %s objects" % base.__name__
  17.  
  18. TypeError: can't pickle DirEntry objects
  19.  
  20. import scandir, pickle
  21.  
  22. s = scandir.scandir("D:\PYTHON")
  23. entry = s.next()
  24.  
  25. # first convert the stat object to st_
  26. st = entry.stat()
  27. st_ = {'st_mode':st.st_mode, 'st_size':st.st_size,
  28. 'st_atime':st.st_atime, 'st_mtime':st.st_mtime,
  29. 'st_ctime':st.st_ctime}
  30.  
  31. # now convert the entry object to entry_
  32. entry_ = {'name':entry.name, 'is_dir':entry.is_dir(),
  33. 'path':entry.path, 'stat':st_}
  34.  
  35. # one may need some other class members also as necessary
  36.  
  37. # now pickle the converted entry_
  38. data = pickle.dumps(entry_)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement