如何将 Python 的 getpass() 重定向到 stderr?
我正在尝试编写一个程序,它将其提示打印到标准错误,并将其输出打印到标准输出,以便我以后可以操作输出。
我对 python 有点陌生,但是 getpass() 的文档 显示我应该能够选择一个流:
getpass.getpass([prompt[, stream]])
我已经尝试了 getpass 的各种参数,但我似乎无法让它在 stderr 中提示。任何帮助将不胜感激,谢谢。
>>> password = getpass.getpass("Password", sys.stderr)
TypeError: unix_getpass() takes at most 1 argument (2 given)
I'm trying to write a program that is going to print its prompts to standard error, and its output to standard out so that I can later manipulate the output.
I'm a bit new to python, but the documentation for getpass() shows I should be able to select a stream:
getpass.getpass([prompt[, stream]])
I have tried a variety of arguments to getpass, but I cant seem to get it to prompt in stderr. Any help would be appreciated, thank you.
>>> password = getpass.getpass("Password", sys.stderr)
TypeError: unix_getpass() takes at most 1 argument (2 given)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getpass.getpass()
的流参数是在 python 2.5 中添加的,在之前的版本中不可用。the stream argument to
getpass.getpass()
was added in python 2.5, and isn't available in prior versions.