python实战===输入密码以******的形式在cmd中展示
2023-09-14 09:12:08 时间
#设置密码输入,显示为****** import msvcrt,sys def pwd_input(): chars = [] while True: try: newChar = msvcrt.getch().decode(encoding="utf-8") except: return input("你很可能不是在cmd命令行下运行,密码输入将不能隐藏:") if newChar in '\r\n': # 如果是换行,则输入结束 break elif newChar == '\b': # 如果是退格,则删除密码末尾一位并且删除一个星号 if chars: del chars[-1] msvcrt.putch('\b'.encode(encoding='utf-8')) # 光标回退一格 msvcrt.putch( ' '.encode(encoding='utf-8')) # 输出一个空格覆盖原来的星号 msvcrt.putch('\b'.encode(encoding='utf-8')) # 光标回退一格准备接受新的输入 else: chars.append(newChar) msvcrt.putch('*'.encode(encoding='utf-8')) # 显示为星号 return (''.join(chars) ) print("Please input your password:") pwd = pwd_input() print("\nyour password is:{0}".format(pwd)) sys.exit()
相关文章
- 【Python成长之路】python并发学习:多进程与多线程的用法及场景介绍
- Python 字符串_python 字符串截取_python 字符串替换_python 字符串连接
- [Python Test] Use pytest fixtures to reduce duplicated code across unit tests
- python字符串截取:截取yaml文件名后3个字符
- [LINK]Python服务器开发一:python基础
- python程序员都在用到5个酷毙的Python工具
- 如何系统地自学Python?Python应该怎么学?
- Python语言学习:Python语言学习之编程语言基础案例综合应用集合(输入带*号的密码/与用户交/根据分数判断优良差/提取txt文档中两人对话内容等)之详细攻略
- Python语言学习之文件夹那些事:python和文件夹的使用方法之详细攻略
- Python编程学习:random.shuffle的简介、使用方法之详细攻略
- Python语言学习:利用python获取当前/上级/上上级目录路径(获取路径下的最后叶目录的文件名、合并两个不同路径下图片文件名等目录/路径案例、正确加载图片路径)之详细攻略
- Python编程语言学习:包导入和模块搜索路径(包路径)简介、使用方法(python系统环境路径的查询与添加)之详细攻略
- 〖Python 数据库开发实战 - MySQL篇㉕〗- 数据更新操作 - UPDATE 语句
- 〖Python 数据库开发实战 - Python与MySQL交互篇⑩〗- 创建新闻管理系统的具体python文件
- python之numpy.ndarray中数据转为int型
- Python编程:安装python环境以及virtualenv虚拟环境
- Python将科学计数法数值转换为指定精度浮点数
- 配置mailx 通过465端口发送邮件 /etc/mail.rc python脚本 发送邮件
- Python:SMOTE算法——样本不均衡时候生成新样本的算法
- python基础===利用PyCharm进行Python远程调试(转)
- python 查看趴下来的数据
- python中logging模块的一些简单用法
- 【Python实战】 ---- python 实现 CSDN 的定时自动签到
- python使用技巧(二十一):class()与class(object)的区别以及object的使用