[英]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. 只需使用try / except块。
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. 尝试使用Cerealizer 。 It might incidentally solve your empty file problem. 它可能会附带解决您的空文件问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.