(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/module-termios.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/module-termios.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/module-TERMIOSuppercase.html| ]]
|
Python Library Reference
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/contents.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/modindex.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/genindex.html| ]]
|
Previous: 8.8 termios Up: 8.8 termios Next: 8.9 TERMIOS
8.8.1 Example
Here's a function that prompts for a password with echoing turned off. Note the technique using a separate tcgetattr() call and a try ... finally statement to ensure that the old tty attributes are restored exactly no matter what happens:
def getpass(prompt = "Password: "):
import termios, TERMIOS, sys
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~TERMIOS.ECHO # lflags
try:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
passwd = raw_input(prompt)
finally:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
return passwd
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/module-termios.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/module-termios.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/module-TERMIOSuppercase.html| ]]
|
Python Library Reference
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/contents.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/modindex.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/20/lib/genindex.html| ]]
|
Previous: 8.8 termios Up: 8.8 termios Next: 8.9 TERMIOS
See About this document... for information on suggesting changes.