I have an object (numpy.ndarray
, for example), that should be passed as an argument to several functions. In C++ in such cases I declared such arguments as const
, in order to show, that they must not be changed.
How can I do the same in Python?
Syntactically, you can't. You have two choices:
pass a copy of your object to these functions - this way, you won't have to worry about it being corrupted
create a wrapper, that implements the required interface, wraps your object, and doesn't allow modifications
The second option is of course only possible if you know what interface is expected and if it's simple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With