Sixteen --reflect reflection

A single directory

commons page

 

 visit page

 

 In order to facilitate file has many functions to prevent the commons leads visit also write more elif, we use the reflection mechanism provided by python. Mainly on its performance in the getattr (), and several other built-in functions

 

 

 getattr = func (commons, inp) , by getattr () function, the module from the commons, and find the same function name string inp and returns it, and then assigned to the variable func. In this case points to the variable function func, func () can call the function.

hasattr (commons, InP) , used to determine whether there is a member of the commons, the return True or False.

Second, and more catalog

Processing functions are placed in a plurality of different modules in different directories in order to reduce a time of the visit in the introduction of n modules , can be used python built __import__ (String parameter) function is solved.

 

 For cross-directory to import the module, plus fromlist = True can! ! ! fromlist = True is to import all catalog

Guess you like

Origin www.cnblogs.com/KeenaCherry/p/12142944.html