“Simpan hal di Pickle Python” Kode Jawaban

Simpan hal di 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
TheProgrammer

Buat python file acar

import pickle
file_name='my_file.pkl'
f = open(file_name,'wb')
pickle.dump(my_data,f)
f.close()
Tremendous Enceladus

Pickle.Load 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)
Doubtful Dingo

Simpan file sebagai acar

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'
Depressed Dogfish

Jawaban yang mirip dengan “Simpan hal di Pickle Python”

Pertanyaan yang mirip dengan “Simpan hal di Pickle Python”

Lebih banyak jawaban terkait untuk “Simpan hal di Pickle Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya