encurtido.cargar python
import pickle
# load : get the data from file
data = pickle.load(open(file_path, "rb"))
# loads : get the data from var
data = pickle.load(var)
guardar cosa 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
crear archivo pickle python
import pickle
file_name='my_file.pkl'
f = open(file_name,'wb')
pickle.dump(my_data,f)
f.close()
cargar desde el archivo pickle
1 # Load the dictionary back from the pickle file.
2 import pickle
3
4 favorite_color = pickle.load( open( "save.p", "rb" ) )
5 # favorite_color is now { "lion": "yellow", "kitty": "red" }
guardar un archivo como un 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'