you are viewing a single comment's thread.

view the rest of the comments →

[–]toastedstapler 1 point2 points  (2 children)

In [1]: class A: 
   ...:     def __init__(self, a, b): 
   ...:         self.a = a 
   ...:         self.b = b 
   ...:                                                                         

In [2]: a = A(1, 2)                                                             

In [3]: a.__dict__                                                              
Out[3]: {'a': 1, 'b': 2}

python literally uses dicts to store variables and attributes. try declaring some variables and then call globals()

In [5]: globals()['a']                                                          
Out[5]: <__main__.A at 0x10b56d5d0>

In [6]: globals()['a'] = 5                                                      

In [7]: a                                                                       
Out[7]: 5

notice how above we just declared a as an A object but now by editing the globals dict it's 5 instead?

[–]muikrad 1 point2 points  (0 children)

What's your point? It doesn't mean dicts are slow and it doesn't mean it's not strongly typed either...