You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are not careful with lists, you can accidentally change variables without meaning to through shallow copies. Is there a way to implement a constants class that can't be accidentally modified?
from typing import NamedTuple
class test(NamedTuple):
blub: int
bla: float
this_test = test(4, 3.2)
this_test.blub = 5 # this will fail, because it's immutable.
This can be used to pass one immutable "parameter object" to a function, instead of passing lots of single parameter which are then also mutable.
If you are not careful with lists, you can accidentally change variables without meaning to through shallow copies. Is there a way to implement a constants class that can't be accidentally modified?
Maybe something like this: https://discuss.dizzycoding.com/can-i-prevent-modifying-an-object-in-python/
The text was updated successfully, but these errors were encountered: