This is literally the most useful pickle video i've seen while trying to learn it so far, thanks a ton
@ReuvenLerner2 жыл бұрын
I'm so happy to hear you enjoyed it!
@aaronhumanistallen61604 жыл бұрын
I really like you're teaching style and would like to say thanks for this content! Cheers.
@Jerryboy972 жыл бұрын
Thank you so much. I was fearing I couldn't save my objects for the future, as they took me nearly an hour to get (65 million iterations of something, yay). I am saved
@ReuvenLerner2 жыл бұрын
I'm so glad to hear it helped!
@sakshiwahi20254 жыл бұрын
Wow. Why aren't there more views on this channel! LOVE the way you teach _/\_
@josephgaviota3 жыл бұрын
Agree; I thought it was very effective too. And the genius of saying "that's an external module, don't worry about that right now" was be very helpful when teaching; often it's easy to get bogged down with the various side-trips which derail the point one is trying to make.
@inzemam52712 жыл бұрын
When you said, "The world should listen to my suggestions more"... It reminded me of my dad. Great video though.
@ReuvenLerner2 жыл бұрын
I hope in a good way!
@inzemam52712 жыл бұрын
@@ReuvenLerner yes 😂
@Momo-bb2fn3 жыл бұрын
Me: _chillin_ Him: *types at 0:44 Me: 👁👄👁
@ethernaut.71273 жыл бұрын
Reuven Lerner : *I am speed* lmao
@rh.m66602 ай бұрын
Top stuff sir. 👍
@ReuvenLerner2 ай бұрын
Glad it helped!
@Morgan-l2d9 күн бұрын
Thank you so much!
@ReuvenLerner8 күн бұрын
My pleasure, glad it helped!
@FusionCorporation-jx5ou2 жыл бұрын
well its a pretty cool stuff, but as you said, pickle sometime do not work for some object. recently i was trying to pickle the object of my stock broker connection and it throwed error that object with the thread lock cannot be pickled
@ReuvenLerner2 жыл бұрын
That's another good example of an object that cannot be pickled!
@thiagoamorim91723 жыл бұрын
Perfect explanation, thank you! I just have one more doubt, how do I make if I wann to store more than one class object in the same file? Example: I have a class "Car", and objects car1 and car2, and my objective is to store car1 and car2 in the "mydata.pkl" file
@ReuvenLerner3 жыл бұрын
Pickle itself doesn't handle more than one object in a file. But there are two ways to get around this: (1) Put the two instances of Car in a list. A list is a single object, and it can be pickled. Ta da! Problem solved. (2) Python's standard library comes with "shelf" (docs.python.org/3/library/shelve.html), which lets you store multiple objects. It's more complex, and it requires that you have a key for each stored object, but it might serve your needs.
@Utkarsh_Kumar2153 жыл бұрын
sir.. please help me resolve my errors.type error- thread.rlock object while pickling , save n load the cnn model
@ReuvenLerner3 жыл бұрын
I'm not sure what to tell you; I'm not really sure if you can pickle thread objects.
@martinocrespoalvarez46634 жыл бұрын
I like you're teaching style as well! Without 6:36 I'd have been looking for my problem for ages... What's the point of pickling a class definition if you have to import it for using it in another file after unpickling it?
@ReuvenLerner4 жыл бұрын
Well, I don't know if you want to pickle a class definition -- it's more common to pickle an instance. But you'll still need the class definition on the other side. Imagine a situation in which you're storing objects in a database, or a filesystem. For example, you might have a machine-learning model that you spent a lot of time training. You'll store the model using pickle, and then load it whenever you want to run some predictions. That's fine, and it'll work great, but you first need to import the class. If you don't do that, things will break.
@josephgaviota3 жыл бұрын
Thanks for that very interesting vid. I type pretty fast, but man, you're _really_ fast! Question: I pickle and unpickle a LOT, and rather than opening a file; save/load data, close file; or even using "with open" (both of which I can do and have done in the past), I always use: my_dict = pickle.load(open('somefile','rb')) pickle.dump(my_dict,open('otherfile','wb'),-1) So, it's a one-liner. Easy as pie. Do you object to that coding style? I've checked, and it doesn't leave any leftover open filehandles. So, I don't think I'm wasting system resource, and the one-line style seems clear to me. [edit: fix typo]
@ReuvenLerner3 жыл бұрын
I think that you're just fine - as you say, there aren't going to be any open file objects when you're done, because there won't be any references to the file you've opened. So looks good to me! As for my typing, blame my parents. They forced me to learn when I was in high school, and it was, hands down (so to speak), the most practical skill I've learned in a long time.
@anwerhassan154 Жыл бұрын
thanks really are wonderful
@ReuvenLerner Жыл бұрын
Glad you're enjoying!
@sahilmane61393 жыл бұрын
How do i resolve 'cant pickle weakref objects'?
@ReuvenLerner3 жыл бұрын
I was about to write that you cannot pickle a weakref. But it turns out that you *can*, assuming that the weakref resolves to a working, active object. If the weakref's object has gone away, then you'll run into trouble. How do you avoid this sort of problem? You could check that a weakref's object still exists before running "pickle," but then you'll have a race condition of sorts. So you might just need to avoid doing it altogether.
@Pedro-kw1ce4 жыл бұрын
Hi there, I appreciate your video. But, I was trying to dump my own class object and this class contains a Simpy environment and I always get "AttributeError: 'Environment' object has no attribute" when I try to load that file to a variable again. I am using tkinter to generate a GUI to dump and load process, it allows me to generate this object too. Do you have any idea on how to figure this out?
@ReuvenLerner4 жыл бұрын
Pickle works with all built-in Python classes, other than a few that cannot be saved or represented there. Your own classes, and packages that come from outside of the standard library, need to include support for pickle; it's not automatic. I don't know anything about Simpy, but it's quite possible that it doesn't support being pickled. I would suggest checking with the Simpy documentation and/or developers to see if it's possible.
@galan81154 жыл бұрын
And if you got a pickle.py file in your pycharm, like i did, it doenst work because it tries to import it/itself instead of using the library :D. Thats why i had to rename my tutorial file from "pickle.py" to "pikle.py"
@ReuvenLerner4 жыл бұрын
Oh, goodness - this is a problem that I'm constantly warning my students about! You have to be careful not to call your program file with the name of a module in the standard library, especially if you're planning to import it. This is, unfortunately, a common mistake. Hmm, maybe I should make a video about it!