Python3 dynamically add attributes, delete properties to determine property function

Dynamically add properties to an object refers to dynamic binding properties outside the class, method of adding two ways:
1. bind directly to the object, for example: p.name = "Tom"
2. Use setattr function: setattr (P , 'name', 'Tom' )
to determine whether an object has a property:
hasattr (the p-, 'name'), returns a Boolean value; can also be used to determine whether an object has a method
to delete an attribute:
del keyword: p.name del
delattr function: delattr (p, 'name' )

Guess you like

Origin blog.51cto.com/13560219/2479011