Discussing self, obj, objtype, and value
00:00 This is going to be a very short lesson, but the concepts here are that important that I wanted to present it as a separate lesson so you can always afterwards easily refer back to it.
00:12
So you’ll remember get, set and delete as the methods of the descriptor protocol. And I’ve also included a bit of code from your example that will help, well, I think anyway.
00:24
So what is self, object, objtype, and value? Let’s start with self. Well get, set and delete are instance methods of the descriptor class.
00:34
So as is the case for any class, self represents an instance of that class. So here self represents an instance of the descriptor class, so StringValidator with parentheses. obj is the class instance that holds the attribute to which the descriptor class instance has been assigned.
00:55
So the attribute we’re talking about is .title and the descriptor class instance is StringValidator with parentheses. So the class instance that holds this attribute is the class Song and it’s an instance of Song().
01:10
It’s an instance because the class itself is represented by objtype. value then finally is just a value to update the attribute value to when using set.
01:24 And with these concepts well understood, you are ready to dive back into the code.
Become a Member to join the conversation.
