I am using pydantic for some user/password data model. When the model is printed, I want to replace the value of password with something else (*** for example) to prevent that the password is e.g. written into log-files or the console accidentally.
from pydantic import BaseModel
class myUserClass(BaseModel):
User = 'foo'
Password = 'bar'
def __str__(self):
return "Hidden parameters."
U = myUserClass()
print(U)
# > Hidden parameters. # Should be User='foo', Password='***' or similar
U # This will still show my password.
#> myUserClass(User='foo', Password='bar')
How can I access the string that is normally printed and replace only 'bar' with '***', but keeping all parameters?
How can I also do that when just calling U? This may not be equally important as for logging and console output usually print is called.