python - How To Get Values of Variable For All Instances of A Class -


I have a Python class with thousands of examples

Each instance has several variables.

For all the examples of class I have to get values ​​of the specific list variable.

I believe this has been done with ...

  __ dict__  

I think the data I just can not seem to get the syntax rights for the requirement.

I know that this is a simple line of code. Anybody know what the code is?

As Klaus D says, you should maintain a manual list. However, if all of these examples are present in the local area of ​​a function, then the code below shows how you can get them. But even if this is possible, I recommend you strongly no to do this

  #! / Usr / bin / env python import random class myclass (): def __init __ (self, data): self.data = data def main (): random.seed (42) # For example, some examples of myclass for i ): Expand all examples of myclass from print s exec (s), local () # in S = "a% 02d = myclass (% d)"% (i, random.randint (0, 99)), globals () Local (for example) (for example) (for example), (for example), for example (example, Q, V) local people in Kashmir,% 2d "% (name, example [name] .data) if __name__ == "__main__": main ()  

output

  a00 = MyClass (63) A01 = MyClass (2) a02 = MyClass (27) A03 = MyClass (22) A04 = MyClass (73) A05 = MyClass (67) a06 = MyClass (89) A07 = MyClass (8) A08 = MyClass (42) A09 = MyClass (2) A00: 63A01: ​​2 a02: 27A03: 22A04: 73A05: 67 a06: 89A07: 8A08: 42a0 9: 2  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -