Class attribute or argument's default value
python
Solution
It's possible to change the default value this way:
Wait.timeout = 20
Will mean that, if unset, the default will be 20.
E.g:
>>> class Wait:
... timeout = 9
... def __init__(self, timeout=None):
... if timeout is not None:
... self.timeout = timeout
...
>>> a = Wait()
>>> b = Wait(9)
>>> a.timeout
9
>>> b.timeout
9
>>> Wait.timeout = 20
>>> a.timeout
20
>>> b.timeout
9
This utilises the fact that Python looks for class attributes if it doesn't find an instance attribute.
Problem
I've found the following open source code in Python: ``` class Wait: timeout = 9 def __init__(self, timeout=None): if timeout is not None: self.timeout = timeout ... ``` I'm trying to understand if there are advantages of the code above vs using default argument's value: ``` class Wait: def __init__(self, timeout=9): ... ```