Download presentation
Presentation is loading. Please wait.
Published byTiffany Morgan Modified over 9 years ago
1
Python Object Model Sambasiva Suda PyCon India
2
Agenda Python Classic Objects Different types of Objects Relationships among objects Q & A
3
Python Object In Python everything IS An Object IS A shows Inheritance object is the root of the inheritance hierarchy Two types of objects – Class objects Class Meta Class – Instance objects (Non class objects) Three relationships – IS A – Instance of – HAS A (Attributes)
4
Relationships Contd HAS A – Basic relation – Attribute IS A – Inheritance – inherits attributes from super object Instance Of – Can access all attributes of parent object except class methods and static methods
5
Python Basic Objects Type Object Meta Class Class Instance Object
6
Class Object class A(object): class_data_attr = ‘sample’ def class_method_attr(self): self.instance_attr = ‘sample2’ #instance object Instance_object = A()
7
Meta Class Object class A(type): metaclass_data_attr = ‘sample’ def metaclass_method_attr(cls): self.class_attr = ‘sample2’ #class object Class B(object) __metaclass__ = A
8
Builtin Objects Diagram type None int float complex str unicode basestring bool long tuple list dict lambda object
9
Attributes Builtin User defined – Dynamic – Stored in __dict__ Dot notation Data attributes Method attributes
10
Descriptor Object __get__(self, instance, owner) __set__(self, instance, value) __delete__(self, instance) Data Descriptors (implements __set__) Non Data Descriptors If attribute is a descriptor, corresponding method will be called
11
Attribute lookup Algo If attrname is a builtin attribute, return it. Look for data descriptors in parent and its bases Look in object.__dict__ for attrname Look for non data descriptors in parent and it bases Look in __dict__ of parent and its bases Raise AttributeError
12
References http://www.cafepy.com/article/ http://docs.python.org/reference/datamodel. html http://docs.python.org/reference/datamodel. html
13
Thank You Very much Q & A
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.