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,

http://blog.csdn.net/xpresslink/article/details/76572442

CodePudding user response:

reference 1st floor zhmwang2008 response:
you what this is all some what

Python3 internal all adopt the unicode all can do it directly in Chinese identifier,

CodePudding user response:

reference xpresslink reply: 3/f
Quote: refer to 1st floor zhmwang2008 response:

You what this is all some what

Python3 internal all adopt the unicode all can do it directly in Chinese identifier,


reference xpresslink reply: 3/f
Quote: refer to 1st floor zhmwang2008 response:

You what this is all some what

Python3 internal all adopt the unicode all can do it directly in Chinese identifier,


So write, there must be other colleagues killed

CodePudding user response:

I am the Lord, please don't care about my code is used in the Chinese or English, please pay attention to the problem! In Britain, France German casually with just a fur, the compiler looks no difference! Debate these are not my original intention this problem

CodePudding user response:

refer to the second floor xpresslink response:
no way is very good, actually 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,

http://blog.csdn.net/xpresslink/article/details/76572442


thank you very much xpresslink answer! I noticed that you put the dictionary again Bob in this instance, again by Bob variable to point to it, this was actually a bit around a circle, because why I avoid using three people at first name directly from the class generation as an example, to generate instance "batch". For example, suppose I have 100 people, so it is impossible to put the name of each of the examples of the variable names, so to write article 100 statements generated instance. So I will use a for loop to iterate generated instance object, then the mass production of the instance variable name how to deal with? Can only use the index to represent, so in the form of a dictionary.
If a python object of mass production, can't get to the properties and methods of automatic prompt, or quite regret.

CodePudding user response:

Python3.6 code hinting function has been added, the variable name behind plus colon and types,

For the name in list_ name:
instance _ people: human =human (name)
[name]=instance _ dict_ instance
  • Related