简体   繁体   English

从 IDLE 运行时“GetPassWarning: Can not control echo on the terminal”

[英]“GetPassWarning: Can not control echo on the terminal” when running from IDLE

When I run this code:当我运行此代码时:

import getpass

p = getpass.getpass(prompt='digite a senha\n')
if p == '12345':
    print('YO Paul')
else:
    print('BRHHH')
print('O seu input foi:', p) # p = seu input

I got this warning:我收到了这个警告:

Warning (from warnings module):
   File "/usr/lib/python3.4/getpass.py", line 63
    passwd = fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal. Warning: Password input may be echoed.

Use an actual terminal -- that is, an environment where stdin , stdout and stderr are connected to /dev/tty , or another PTY-compliant device.使用实际终端——即stdinstdoutstderr连接到/dev/tty或其他 PTY 兼容设备的环境。

The IDLE REPL does not meet this requirement. IDLE REPL 不满足此要求。

Run your code in terminal, instead of the IDE.在终端而不是 IDE 中运行您的代码。 you will see that there is no more warning there.你会看到那里不再有警告。 To run your code, enter this command in terminal:要运行您的代码,请在终端中输入以下命令:

python3 your_program.py

Rather than deal with changing the current working directory in a terminal that has not started Python (which would mean you type something like python3 script.py --and it will fail unless the current working directory is already specified), start Python in your terminal and run this one-line command:与其在尚未启动 Python 的终端中更改当前工作目录(这意味着您键入类似python3 script.py ——除非已指定当前工作目录,否则它将失败),而是在终端中启动 Python并运行这个单行命令:

exec(open('C:\\folder\\script.py').read())

where you change the path string 'C:\\folder\\script.py' to match wherever your file is located on disk (the string does need to be specified with quotes).在其中更改路径字符串'C:\\folder\\script.py'以匹配文件位于磁盘上的任何位置(该字符串确实需要用引号指定)。

use cmd ie.使用 cmd 即。 command prompt and then run the file in it.命令提示符,然后运行其中的文件。

like:像:

python abc.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM