Introduced
Learning record ....
Directory:
-
Object-oriented Advanced Syntax section
Special member reflection of the classical class of modern class class
Class
-
Field
-
-
Normal field
-
Static fields
-
Method
-
-
Common methods
-
Class method
-
Static methods
-
Property
-
-
Normal properties
-
Private properties
Field
Ordinary fields belong to the object, instance variables, exist in each instance, when the instance, open an instance object,
Static fields belong to the class, class variables, in memory exist in the class, no instantiation, also exist.
Method
class animal: def __init__ (Self,name): self.name=name hobbie = ' Meat ' @ classmethod # #类方法, cannot access instance variable def talk (self): print ("{} is talking". Format (Self.hobbie)) @staticmethod # #静态方法, cannot access class variables and instance variables, most of the cases do not, the class's Toolbox def walk (): print (" is talking") @property # #属性, the following is not a method, it becomes a property, but you can still access instances and class variables def Habit (self): print ("{} habit is xxoo ". Format (Self.name)) d = animal (" Hequan ") Animal.talk () D.talk () D.walk () d.habitmeat is talkingmeat is talking is talkinghequan habit is xxoo
Private Properties __
Self.__num=num
Classic class: Limited depth
New class: Breadth First
Special members of the class
-
__doc__ Printing Notes
-
__MODULE__ represents the object of the current operation in that module
-
__CLASS__ represents the class of the object that is currently being manipulated
-
__init__ constructs a method that automatically triggers execution when an object is created through a class
-
The __del__ destructor automatically triggers execution when the object is freed in memory. After the execution is complete, it is destroyed uniformly.
-
The __call__ object is appended with parentheses, triggering execution
-
__DICT__ View all members in a class or object,
-
__new__ \ __metaclass__ the class's build call order is __new__---__call__--and __init__
Reflection
Mapping or modifying the state, properties, methods of a program while it is running through a string
-
Hasattr
-
GetAttr
-
SetAttr
-
Delattr
If __name__== "__main__":
Server = WebServer (' localhost ', 3306)
If Hasattr (Server,sys.argv[1]):
Func = GetAttr (server,sys.argv[1]) # #获取执行后面加的值 like start
Func ()
This article is from the "what-all" blog, please be sure to keep this source http://hequan.blog.51cto.com/5701886/1886936
python--day7--advanced Object-oriented programming