Guardar cosa en pickle python

Ejemplos de código

15
0

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)
7
0

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
5
0

crear archivo pickle python

import pickle
file_name='my_file.pkl'
f = open(file_name,'wb')
pickle.dump(my_data,f)
f.close()
-1
0

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" }
-1
0

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'

Páginas relacionadas

Páginas de ejemplo relacionadas

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................