Because I did not want to expose my passwords in plain text whenever an exception was thrown or inside the debugger, I wrote this simple snippet. It's very simple, but can be quite useful nonetheless...
1 2 3
class passwd(str): def __repr__(self): return repr('*' * self.__len__())
To demonstrate its use, here some examples:
>>> astr = 'aString' >>> astr 'aString' >>> print astr aString >>> apwd = passwd('aPassword') >>> apwd '*********' >>> apwd == 'aPassword' True >>> print apwd aPassword
More important, the password string will not immediately show up in your debugger in plain text or in exception frames, since __repr__ is used for those cases.