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?
1 Answer. Show activity on this post. pickle doesn't work that way: an empty file doesn't create an empty list.
Python Pickle dump dump() function to store the object data to the file. pickle. dump() function takes 3 arguments. The first argument is the object that you want to store. The second argument is the file object you get by opening the desired file in write-binary (wb) mode.
To use pickle to serialize an object, we use the pickle. dump function, which takes two arguments: the first one is the object, and the second argument is a file object returned by the open function. Note here the mode of the open function is 'wb' which indicates write binary 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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With