Home > other > Mass production of python, use a dictionary to store instance objects, called objects, unable to aut
Mass production of python, use a dictionary to store instance objects, called objects, unable to aut
Time:10-02
For example, I have a "human"
Class human (object) : Def __init__ (self, name) : The self. The name=name Def call (self, the other party's name) : Print (self. The name, 'is talking to... ', the other party's name)
List_ name=[' Alice ', 'Bob', 'clark'] Dict_ instance={} # used to store all the object
For the name in list_ name: Instance _=human (name) Dict_ instance [name]=instance _
Call dict_ instance [' Bob ']. (' I ') # here is you can call to call "human" in the method, however, a code, but not automatically prompt any class (or objects) owned properties and methods, how to solve this problem? [/size]
CodePudding user response:
This is what you what ah
CodePudding user response:
Actually not very good way, this is one of the shortcoming of dynamic language, static analysis is difficult, Until the script is running, the object actually generated, at the same time, not the type of static description IDE cannot be inferred, The IDE support for built-in object code completion is relatively good,
Can only use some alternative methods such as
In order to this problem I have written a blog, in a nutshell this way,