1, double underline (__)
Properties that start with a double underline are confused at run time, so direct access is not allowed. Properties that actually start with a double underline
Will precede the explanation with an underscore and a class name, such as Self.__num will be parsed as Self._classname__num,
2, Single underline (_)
Simple module-level privatization you only need to use a single underline character before the property name. This prevents the properties of the module from being
From mymodule Import * loaded. Because this is strictly based on the scope, it is also useful for functions.
3. Authorization
Authorization is a feature of packaging that can be used to simplify processing of dictating functions and to use existing functionality to achieve maximum
Limitation of code reuse.
The key point to implementing authorization is to overwrite the __getattr__ () method, example:
Class Wrapme (object):
def __init__ (self,obj):
self.__data=obj
def __getattr__ (self,attr):
return GetAttr (self.__data,attr)
w = WRAPME (3.5+4.5j) w.real 3.5 w.imag 4.5 w.conjugate
()
(3.5-4.5j)
The Real,imag,conjugate property passed here is authorized by GetAttr to the Wrapme object. Remove __getattr__
When you access properties such as real, you will be prompted that the property does not exist.