Placeholder Image

字幕表 動画を再生する

  • what is going on?

  • Everybody.

  • And welcome to another sockets with python tutorial video.

  • In this video, we're gonna be talking about pickles, not the food, but instead the serialization in python.

  • So real quick.

  • If you don't know what pickling is in Python, it is tthe e serialization, or I think we can call that flattening as well and there's probably other terms for it.

  • What does that mean?

  • We're converting it to bites.

  • What are we doing with bites with sockets?

  • We're sending them.

  • So putting that all together means we can send and receive things we've pickled in python via sockets.

  • Now what can we pickle in python objects and what's an object in python?

  • Everything.

  • So we can pickle pretty much everything in python.

  • And basically, what this means for us with sockets is that we can send and receive thes python objects.

  • So anything that we're doing in a python script, we can send and receive that, you know, whatever it might be.

  • Maybe you're training a machine learning model and you want to share that model amongst many machines or you've got some sort of shared database or you know who knows what what exactly you're doing.

  • Just you know that you can send and receive that information with Python.

  • So any object you haven't Python Any data structure, Whatever it, you can serialize it with pickle and then send it.

  • So that's what we're gonna be doing here s O.

  • If you don't know any.

  • If you already know things about pickle, don't worry.

  • We're gonna send and receive exactly what I'm gonna build here.

  • If you don't know anything about pickle, it's pretty simple.

  • So we're gonna go import pickle.

  • And just for the record, you can also save pickles as files so you don't Onley transmit pickled data like between two programs.

  • Many times you're actually just going to save that python object using pickle.

  • Anyway, uh, so the first thing we want to do is just come up with some sort of example of the thing that we're gonna save.

  • So I'm gonna say it's just we're gonna use a dictionary for now.

  • Just anything are some arbitrary python objects?

  • Uh, we'll do so we'll just say Hey there.

  • Okay, that's the object we want to send.

  • But again, it doesn't have to be a dictionary.

  • And also, if you were doing a dictionary.

  • You also could just use, like, Jason or something like you convert it to a string.

  • Senators by its converted back out.

  • He's Jason would be good to go.

  • So you don't Actually, you wouldn't use pickle for probably a dictionary.

  • But again, you can use pickle for anything.

  • Whereas, like, Jason is one structure, you wouldn't be able to do everything with Jason.

  • So Okay, so that's the thing that we want a pickle.

  • So how do we do that?

  • Well, we're going to just say message.

  • The message will receive later is going to be pickled dot dump S D.

  • And we can just print message real quickly to see Okay, here's what we've got.

  • Basically, we do have the string data that we can see here.

  • Um, we also I don't see the number, but it's probably there somewhere.

  • Anyway, um, and then we've got some godly group.

  • That is the, um, the information that is contained within the actual structuring of what a dictionary is and how we can interact with it and all that cool.

  • So now we want to send this information.

  • So let's go and do that.

  • So I'm gonna cut that.

  • Come over here.

  • Come down here.

  • Fix that.

  • Okay.

  • Get rid of this loop.

  • We don't We're not gonna loop anymore.

  • And the message?

  • Now, uh, let me just get rid of the 1st 1 paste this one in.

  • So now our message is that pickle dump.

  • But we also we still want to use that header again.

  • Because the thing we pickle might very easily exceed our buffer signs.

  • So we need to be able to handle for that.

  • So the way that we're gonna do that is actually going to be will convert this cause this is already bites, right?

  • So we just need to convert this two bites, so bites that.

  • And then what kind of bites?

  • Utf eight bites?

  • Okay, so that's the message that we want to send.

  • We no longer have to convert it here.

  • Two bites because it's already bites and we're good to go on the server now.

  • We just need to fix a few things on the client side.

  • The first thing would be the full message here.

  • Should be bites then, uh, the information that we want to receive should be pretty much all the same.

  • The only thing I wouldn't do you no longer are we gonna decode UT f A.

  • It's just gonna be message.

  • When the full message is received, we're gonna unpick lit.

  • So it's going to import pickle.

  • Come down here.

  • Um, so full message received.

  • Here it is, But first, we need to load it in.

  • So we're just going to say, copy that we're gonna say d equals pickle dot Load s that thing.

  • And then let's print d save that.

  • Come over here.

  • And now let's run these two things.

  • Python server, that pie.

  • Good to go.

  • And finally, Python client got pie.

  • So full message received.

  • This is what it looks like to us because I'd also contains.

  • Actually, I can't remember if we turned off the header anyway for Mrs Received looks something like that.

  • Once we've loaded it with pickle, there's our actual python object that we sent using pickles.

  • So super cool.

  • If that doesn't excite you, you're either not nerdy enough or you just don't understand, because now you can send literally anything and python that you're working with.

  • So if you got some script, it's doing something.

  • You've got two scripts that can share this data between each other, either locally or remotely.

  • So that's fucking awesome.

  • Speaking of awesome, Quick shadow to my most recent channel members is obey a shower.

  • You are amazing, Curiel.

  • Grow shin cough.

  • Just just incredible.

  • Henri de Meena.

  • Awesome.

  • And soon, Dar Bolaji Spectacular.

  • Thank you guys very much for your support.

  • You guys are all awesome.

  • So that's it for now.

  • In the next tutorial, I think we're going to wrap everything up with a an example with a chat bond or not, Chap who wants a chat bought any time I say chat.

  • I wonder if I've made that mistake so far in this series anyways.

  • Probably.

  • Anyway, I wanna make a chat server.

  • Eso That'll kind of bring everything together and allow us to show one Maur concept that we haven't yet shown.

  • Select.

  • Um, and yet it would be pretty cool.

  • So anyway, questions, comments, concerns, whatever feel free living below, you can also join the discord.

  • Discord dot g slash Centex.

  • If you want to support the champion, click that beautiful blue doing button that just beckons for you to click on it.

what is going on?

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B2 中上級

Pythonによるソケットチュートリアル 3 パート3 - PickleによるPythonオブジェクトの送受信 (Sockets Tutorial with Python 3 part 3 - sending and receiving Python Objects w/ Pickle)

  • 8 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語