From the course: Advanced Python: Object-Oriented Programming
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Solution: Event from JSON - Python Tutorial
From the course: Advanced Python: Object-Oriented Programming
Solution: Event from JSON
(energetic music) - [Instructor] Let's take a look at my solution. So here we have the LoginEvent, and the AccessEvent unchanged. And what I'm creating, hold on, let me run it first, and hide the files. Okay, so now what I'm going to do is I'm going to import from ABC and import json because we're doing JSON Serialization, and I'm creating a serialized class. This is going to be an ABC class, meaning it's going to have at least one abstract method, which is the notify_loaded, and then it has a classmethod because this is an alternate constructor from json, which gets the data. It does json.load the data and then call the instance with the class and then call notify_loaded and returns the instance. So let's run this one first time. And now we create the mixing classes. We have SerializeLogin, which is a LoginEvent, and Serialized, and we have SerializedAccess, which is an AccessEvent, and Serialize. Once we have these two, we can run our code. So we have the login data and the access…