First, the object-oriented Advanced Syntax section
1. Static methods, class methods, property methods
2. Special methods of Class
3. Reflection
Second, exception handling
Third, Socket Development Foundation
First, the object-oriented Advanced Syntax section
static methods (@staticmethod)
Definition: only nominal collation management, in fact, in a static method can not access the properties of the class or instance
1 classDog (object):2 def __init__(self,name):3Self.name =name4 5 @staticmethod6 defEat (x,s):7 Print("%s is eating%s"%(x,s))8Dog.eat ("DF","fdasf")9"" DF isEating fdasf
class method (@classmethod)
Definition: class methods can access only class variables and cannot access instance variables
1 classDog (object):2Name ="444"3 def __init__(self,name):4Self.name =name5 6 @classmethod7 defEat (self):8 Print("%s is eating"%(self.name))9 TenD = Dog ("Zhangsan") One d.eat () A"" 444 isEating
Property Method (@property)
Definition: Turn a method into a static property
1 classDog (object):2 def __init__(self,name):3Self.name =name4 5 @property6 defEat (self):7 Print("%s is eating"%self.name)8 9D = Dog ("Zhangsan")Ten d.eat () One"" TypeError:'Nonetype'Object is notCallable
1 correct method of invocation2 classDog (object):3 def __init__(self,name):4Self.name =name5 6 @property7 defEat (self):8 Print("%s is eating"%self.name)9 TenD = Dog ("Zhangsan") OneD.eat#eat Not added ()
Special members and methods of the class
1, __doc__, print the description of the class information
1 classDog (object):2 " "3 Here is the description information4 " "5 def __init__(self,name):6Self.name =name7 8 defEat (self):9 Print("%s is eating"%self.name)Ten One Print(Dog.)__doc__) A>>> here is a description of the information
2,__module__ and __class__
Python path-python (object-oriented advanced)