Ejemplo 1: guardar algo en pickle python
import pickle
a = {'hello': 'world'}
with open('filename.pickle', 'wb') as handle:
pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL)
with open('filename.pickle', 'rb') as handle:
b = pickle.load(handle)
print a == b
Ejemplo 2: crear python de archivo pickle
import pickle
file_name='my_file.pkl'
f = open(file_name,'wb')
pickle.dump(my_data,f)
f.close()
Ejemplo 3: guardado de pepinillos
import pickle
pickle.dump( favorite_color, open( "save.p", "wb" ) )
favorite_color = pickle.load( open( "save.p", "rb" ) )
Ejemplo 4: pickle load pickle file
pickle_in = open("dict.pickle","rb")
example_dict = pickle.load(pickle_in)
Ejemplo 5: guardar objeto pickle python
import pickle object = Object() filehandler = open(filename, 'w') pickle.dump(object, filehandler)
Ejemplo 6: guardar un archivo como pepinillo
with open('mypickle.pickle', 'wb') as f:
pickle.dump(some_obj, f)
# note that this will overwrite any existing file
# in the current working directory called 'mypickle.pickle'
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)