问题描述
我正在尝试使用python在命令行中创建一个登录面板。因此,如果用户未插入任何username
,则光标应保持在同一行,但下一行会出现错误。
我尝试过:
while True:
input1 = input('username: ')
if len(input1) == 0:
print("Sorry,your response was not loud enough.")
continue
input2 = stdiomask.getpass('pasword: ')
if len(input2) == 0:
print("Sorry,your response was not loud enough.")
continue
input3 = stdiomask.getpass('cnf password: ')
if len(input3) == 0:
print("Sorry,your response was not loud enough.")
continue
但是由于我使用的是while
循环,所以如果我不插入密码,则必须再次插入用户名,如果我不插入用户名,我也不想插入用户名,则提示用户名显示错误后的下一行。那么有什么办法可以处理这些情况?
类似这样的东西:
F:\new_file\file> python main.py
? username: # cursor remains here until a username is inserted
> Invalid input # error is prmpted on next line
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)