On Sat, Aug 11, 2012 at 9:51 PM, eryksun <[email protected]> wrote: > On Sat, Aug 11, 2012 at 11:19 PM, Richard D. Moores <[email protected]> > wrote: >> >>> To clarify, you can store multiple pickles in a file, but each needs >>> its own load. So you'd have to maintain a session dictionary for the >>> factors of new integers. Then append the pickled session to the file >>> when the user quits. When the program starts you'd have to loop >>> through the file to update D with each pickled session. >> >> Isn't that essentially what my script does? > > On line 69 your script (http://pastebin.com/SNwKRuSK) appends the > current D to the end. So only the last pickle appended would be > complete. My first response was for you to switch to 'wb' mode to > truncate the file and only save the latest complete session. > > Then it occurred to me that you actually wanted to grow the pickle the > file. I proposed the above solution to append the new factorizations > per session. Then at the start load the pickled sessions in a loop, > updating D with each loaded dictionary. For example:
OK, thanks for the code, which I will duly study. However, I just pasted my new version, pickle_attempt_for_web2.py at <http://pastebin.com/EZUKjPSk>. I've tested it and tested it, and it does exactly what I wanted (thanks to you!). Yes, you're correct, I want to grow the pickle file, the dictionary. The new version puts every new item into it -- nothing gets lost. One caveat is that I have yet to fix the problem with lines 75-78. One thing I'd like to implement is a monitor of the time factorsOfInteger(n) takes to process some of the 18-digit ints (line 153). Most are processed within a second or two, but some can take several minutes. I'd like to limit the time to 15 or 20 seconds, but is there a way to do this? Just a wild guess, but is this where threading would be useful? Dick _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
