Using The Python Pickle Module

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Seeing this just after watch your newest content make me realize how much improvement you have done

Engiction
Автор

Great stuff! I watched 3 other pickle videos before this one and you got straight to the point. Exactly what I was looking for.

slycooper
Автор

hi, sorry if I write comment in your oldest content . I dont want many people to read.

Anyways, I was just starting my bootcamp lately. After I graduate from my college, I dont have a stable job yet. I found that doing data analysis is very amusing for me and thought this would be my passion career. Life is full of downs this couple years and maybe even it's a little bit late for me to learn everything. I still want survive this nightmare, and live, and have a good job. Your youtube shorts content inspires me to learn python more. So thank you so much. If I may, may I paraphrase and remake your codes with my own language then post it in my github? I also really want to share the codes to my newvie bootcamp friends. Please reply me anytime you have chances, ok 😊

Beg you a pardon if my grammar is still bad.

aryaoctav
Автор

To not have a problem with not having a class, you can do something like this:
import pickle
import inspect

class SimpleClass:
def __init__(self, value):
self.value = value

# Get the source code of the SimpleClass class as a string
class_str =

# Create an object of the SimpleClass class
obj = SimpleClass(10)

# Convert the object to bytes
obj_bytes = pickle.dumps(obj)

# Create a dictionary that contains the class string and the object bytes
data = {'class_str': class_str, 'obj_bytes': obj_bytes}

# Open a file for writing
with open('simple_class.pickle', 'wb') as f:
# Write the data dictionary to the file
pickle.dump(data, f)
Then load it:
import pickle

# Open the file containing the pickled data dictionary
with open('simple_class.pickle', 'rb') as f:
# Load the data dictionary from the file
data = pickle.load(f)

# Extract the class string and the object bytes from the data dictionary
class_str = data['class_str']
obj_bytes = data['obj_bytes']

# Execute the class string to define the SimpleClass class
exec(class_str)

# Convert the object bytes back to an object
obj = pickle.loads(obj_bytes)

# Now the SimpleClass class is defined and you can use the obj object as a normal object of that class
print(obj.value)

Sinke_
Автор

First! Your videos are wonderful, dude! ♥

sonicxskylar
Автор

So pickle is like JSON but binary instead of readable text?

histrion
Автор

do you heard about pep-8? var = value; 9 * self.fat, etc.

aciddev_
Автор

Next time use zoom, very hard to read text

Cruzylife