1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| >>> try:
... import cPickle as pickle
... except ImportError: # cPickle n'est pas disponible
... import pickle
...
>>> f = open("testPickle.dat", "wb") # Ouvrir en ecriture binaire
>>> tableau = ["Hello", "World", "!"]
>>> pickle.dump(tableau, f, pickle.HIGHEST_PROTOCOL)
>>> tableau2 = ["Good", "Bye"]
>>> pickle.dump(tableau2, f, pickle.HIGHEST_PROTOCOL)
>>>
>>> f.close()
>>>
>>> f = open("testPickle.dat", "rb")
>>> print(pickle.load(f))
['Hello', 'World', '!']
>>> print(pickle.load(f))
['Good', 'Bye'] |
Partager