简体   繁体   中英

How to pickle a empty file?

I want to pickle a file that sometime's is empty. Right now its empty, but my idea is that its going to grow over time.

How do i check if a file is "pickable" since it seems that you can not pickle a empty file?

Simply use a try/except block.

def example():
  try:
    return pickle.loads("")
  except EOFError:
    return None

It's easier to ask forgiveness than permission. :)

Pickle is considered unsafe. Try Cerealizer instead. It might incidentally solve your empty file problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM