Python Save Sets To File On Windows Shutdown?
问题 I do not want to lose my sets if windows is about to shutdown/restart/log off/sleep, Is it possible to save it before shutdown? Or is there an alternative to save information without worring it will get lost on windows shutdown? JSON, CSV, DB? Anything? s = {1,2,3,4} with open("s.pick","wb") as f: # pickle it to file when PC about to shutdown to save information pickle.dump(s,f) 回答1: you can detect windows shutdown/log off with win32api.setConsoleCtrlHandler there is a good example How To