On Sun, Aug 12, 2012 at 2:13 AM, Richard D. Moores <rdmoo...@gmail.com> wrote: . > But what > about case where factors.dat is empty? Is there a test for that?
I just discovered os.path.getsize('factors.txt') and that factors.txt has a size of 2 bytes when "empty". (I changed the file extension to .txt so I could delete the contents.) So I now have =============================== D = {} if os.path.getsize('factors.txt') == 2: #The file exists, but is empty: leave it alone pass elif os.path.exists('factors.txt'): #The file exists and is not empty: use it f = open("factors.txt", 'rb') data = pickle.load(f) f.close D = data else: # create the file and close it f = open("factors.txt", 'wb') f.close ========================== which seems to work just fine for all cases. Those lines would replace lines 74-78 in <http://pastebin.com/EZUKjPSk> Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor