I am a complete Python novice so my question might seem to be dumb. I've seen there are two ways of assigning values to object attributes in Python:
Using __dict__:
class A(object):
def __init__(self,a,b):
self.__dict__['a'] = a
self.__dict__['b'] = b
Without __dict__:
class A(object):
def __init__(self,a,b):
self.a = a
self.b = b
Can anyone explain where is the difference?
__dict__approach is that it'll also allow you to create attributes like'a b', but then you can't access such attributes without using__dict__becausea bis an invalid variable name in python.__dict__.