本文整理汇总了Python中msvcrt.putch方法的典型用法代码示例。如果您正苦于以下问题:Python msvcrt.putch方法的具体用法?Python msvcrt.putch怎么用?Python msvcrt.putch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msvcrt
的用法示例。
在下文中一共展示了msvcrt.putch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: win_getpass
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import putch [as 别名]
def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return fallback_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putch(c)
pw = ""
while 1:
c = msvcrt.getch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putch('\r')
msvcrt.putch('\n')
return pw
示例2: win_getpass
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import putch [as 别名]
def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return default_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putch(c)
pw = ""
while 1:
c = msvcrt.getch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putch('\r')
msvcrt.putch('\n')
return pw
示例3: win_print_tty
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import putch [as 别名]
def win_print_tty(string='', indents=0, newline=True, msvcrt=None):
string = str(indent(indents) + string)
for c in string:
try:
msvcrt.putch(bytes(c.encode()))
except TypeError:
msvcrt.putchc(c)
if newline:
try:
msvcrt.putch(bytes('\r'.encode()))
msvcrt.putch(bytes('\n'.encode()))
except TypeError:
msvcrt.putch('\r')
msvcrt.putch('\n')