In a pickle with pickling in python -


i have gone through website , many others no 1 seems give me simplest possible answer. in scrip bellow there 2 different variables need placed single pickle (aka 'test1' , 'test2'); wholly unable simpler 1 of 2 load. there no error messages or anything, , appear being written pickle close 'program', re open it, try load pickle value of 'test1' not change.

the second question how save both same pickle? @ first tried using allstuff variable store both test1 , test2 dumping allstuff...the dump seems success loading jack. ive tried variation list each file should loaded caused whole lot of errors , caused me assault poor old keyboard...

please help.

import pickle  class testing():      test1 = 1000     test2 = {'dogs' : 0, 'cats' : 0, 'birds' : 0, 'mive' : 0}       def saveload():             check = int(input(' 1. save  :  2. load  : 3. print  : 4. add'))             allstuff = testing.test1, testing.test2             savefile = 'testingsaveload.data'              if check == 1:                 f = open(savefile, 'wb')                 pickle.dump(testing.test1, f)                 f.close()                 print()                 print('saved.')                 testing.saveload()               elif check == 2:                 f = open(savefile, 'rb')                 pickle.load(f)                 print()                 print('loaded.')                 testing.saveload()                       elif check == 3:                 print(allstuff)                 testing.saveload()              else:                 testing.test1 += 234                 testing.saveload()   testing.saveload() 

the pickle.load documentation states:

read pickled object representation open file object file , return reconstituted object hierarchy specified therein.

so need this:

testing.test1 = pickle.load(f) 

however, save , load multiple objects, can use

# save pickle.dump(allstuff, f)  # load allstuff = pickle.load(f) testing.test1, testing.test2 = allstuff 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -