[Python-Dev] Could getpass use streams other than stdin? (original) (raw)

Mike Brown mike at skew.org
Fri Aug 13 00:26:23 CEST 2004


On posix, it would be useful if I could have getpass.getpass() write the prompt to stderr or to an arbitrary stream (file-like object), rather than always writing to stdin.

In my use case, I need to send the results of a command-line script to stdout after the user authenticates, and the user may be redirecting stdout, so I don't want the password prompt to pollute the output. If I could have the "Password: " show up in stderr, that would be ideal.

I don't think this would be terribly difficult to implement an API like

def getpass(prompt='', stream=None) if stream is None: stream = sys.stdin ...

but I'm unsure of the nuances of termios and arbitrary streams. Would it be better to just make the choice be between stdin and stderr? -- in which case the API would be something like

def getpass(prompt='', use_stderr=False)

Or is the whole exercise a waste of time?

Thanks



More information about the Python-Dev mailing list