
Python has a set of protocols that the language internally adhere to which provides the functionality for features such as iteration, context manager behavior, string representation of an object, and many other things. When you create custom classes in Python and make use of these protocols then you can create custom behavior in the context of iterations, types, comparison of objects, operator overloading, and much more. Knowing about these will help level up your Python skills. If you are ready to progress forward in your Python prowess, then join us to learn more about the Python data model.
In this episode, Justin and Mike start exploring the Python protocols for creating and initializing object instances. Justin explores the differences between the new and init methods as well as when to consider using those methods.
In this episode, Justin and Mike start exploring how you can represent an object for an output operation. Moreover, Justin discusses the nuanced differences between the str and repr methods as part of the Python data model protocol.
In this episode, Justin and Mike continue the exploration of output representations. Justin demonstrates the usage of the format method in order to provide custom string template formatting for users.
In this episode, Justin and MIke explore one final representation method that can be implemented in Python. Specifically, Justin demonstrates both a simple way to create a bytes object from a class as well as other processes that can be used when writing a custom bytes method.
In this episode, Justin and Mike explore creating code when an object instance is deleted using the del method. Moreover, Justin discusses some of the pain points that can arise when relying on the del method within Python.
In this episode, Justin and Mike explore how a custom class can work with iteration. Justin discusses the implementation of iter and next methods in order to create a custom iterable.
In this episode, Justin and Zach explore how you can replicate dictionary-like behavior when creating a class. Justin explores the implementation of the getitem method in order to bring access of values by keys just like a dictionary.
In this episode, Justin and Zach explore further adding dictionary-like behavior by providing the ability to set and delete values from an object. Justin highlights the details necessary in order to use setitem and delitem to further add dictionary-like behavior.
In this episode, Justin and Zach take a look at the ability to coerce a custom object to True or False based on the bool methods.
In this episode, Justin and Zach explore creating a custom comparable that will allow the equal and not equal comparisons on custom objects.
In this episode, Justin and Zach, further expand on the ability of custom objects to be less than, less than or equal to, greater than, and greater than or equal to using the lt, le, gt, and ge methods.
In this episode, Justin and Daniel explore using custom objects in sets and dictionaries and the effects of overriding the hash method when using custom objects in sets and dictionaries. Additionally, Justin discusses how to handle some of the 'gotchas' using slots for the object.
In this episode, Justin and Zach make use to the add and radd methods to provide custom objects to be used with the "+" operator.
In this episode, Justin and Zach demonstrate the "-" operator overriding using the sub, rsub, and isub methods.
In this episode, Justin and Zach add the ability to multiply two custom objects using the mul, rmul, and imul methods.
In this episode, Justin and Zach review some of the "gotchas" with division in the Python world. Moreover, Justin demonstrates how custom objects can be divided using the floordiv, truediv, and associated methods.
In this episode, Justin and Zach continue building custom objects that emulate numeric types by exploring mod and pow to provide the ability to find the modulus as well as raise the object to a power.
In this episode, Justin and Zach dive into customizing the bit-shifting operations for a custom object using rshift, rrshift, lshift, rlshift, ilshift, and irshift.
In this episode, Justin and Zach continue with bit operations by creating custom behavior for the bitwise or, xor, and and using the and, or, xor, rand, ror, rxor, iand, ior, and ixor.
In this episode, Justin and Zach start looking at the custom implementation of unary "+" and "-" operators using the pos and neg methods.
In this episode, Justin and Zach discuss the creation of custom objects that can have an absolute value and inverse using the methods abs and invert.
In this episode, Justin and Zach explore converting custom objects to their float and integer representation using the methods int and float.
In this episode, Justin and Zach demonstrate how custom objects can be rounded if they are emulating a numeric type using the round method.
In this episode, Justin and Zach utilize the floor and ceil methods to obtain the floor and ceiling representation of a custom objects if the objects are emulating numeric types.
In this episode, Justin and Daniel look into a couple of different data model methods, trunc and index. Utilizing the trunc method, Justin demonstrates how to truncate the representation of a numerical-like object. Moreover, Justin explores the use of an object as an index in a list.
In this episode, Justin and Daniel continue investigating the Python data model by exploring how to represent a numeric type as a complex number utilizing the complex method.
In this episode, Justin and Daniel revisit the idea of looking up information contained within an object. Justin demonstrates the reading of attributes and customizing that behavior using the getattr method.
In this episode, Justin and Zach hijack the setting and deleting of attributes on custom objects using setattr and delattr.
In this episode, Justin and Zach discuss the idea of descriptors briefly when considering a property that needs either to be dependent or have custom logic associated with generating the value. Justin demonstrates the use of the property decorator to define custom object properties that adhere to the "get", "set", and "delete" paradigm.
In this episode, Justin and Zach discuss and implement a custom descriptor object. Additionally, Justin demonstrates how to use a descriptor as a property in another class.
In this episode, Justin and Daniel explore how to make a custom object behave like a function using the call method. Justin further discusses why you would want to have an object that is callable.
In this episode, Justin and Daniel demonstrate how you can make a custom object work with context managers using the enter and exit methods.
In this episode, Justin and Daniel explore the nuances of copying objects with special attention to the difference between copy and deepcopy. Additionally, Justin demonstrates how to override the copy and deepcopy to provide custom copy behavior.
In this episode, Justin and Daniel discuss and demonstrate customizing the behavior of the pickle module when pickling and unpickling an object using the getstate and setstate methods
Python Data Model
Python has a set of protocols that the language internally adhere to which provides the functionality for features such as iteration, context manager behavior, string representation of an object, and many other things. When you create custom classes in Python and make use of these protocols then you can create custom behavior in the context of iterations, types, comparison of objects, operator overloading, and much more. Knowing about these will help level up your Python skills. If you are ready to progress forward in your Python prowess, then join us to learn more about the Python data model.
Course Format
• Binge-worthy TV shows! Watch comprehensive, in-depth episodes that use a talk show-like format to keep you engaged while learning.
• You can pick and choose episodes or you can watch as a complete series.
• A little humor, anecdotes, and real-world examples.
Other Courses
Ready to a DevPro? Get more DevProTV training with a variety of topics. Join Justin and DevProTV to level up your programming prowess!
Updates and Versions
The programming world updates at a break neck pace. As a result, there are times that certain tools, editors, libraries have changed. While syntax or names may change, the foundations remain the same. Though we hope to keep things updated, there may be time before that can occur. I recommend seeing if you can translate between changes and if all fails, ask questions!