tags:

views:

57

answers:

2

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?

A: 

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

Ed Guiness
+2  A: 

Simply use a try/except block.

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

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

badp
I did something a little different... i read the filesize, and if greater then 0 then depickle it! :-) Altho try/catch is a much better solution!My first app for the Nokia N900 btw, YAY!
Jason94
@Jason, maybe for the next version do give a look at Cerealizer. [`pickle` can be used for arbitrary code execution.](http://nadiana.com/python-pickle-insecure)
badp
@badp, the problem is that im realy fresh when it comes to python and on top of it im just trying somethings on my mobile phone (nokia N900). it runs linux so im really far out now. So downloading other stuff and so on is a bit into the future :D <3 Windows/visual studio love! :P cool mobile doh :D
Jason94