我有一个 new.py 文件,我用它来自动化一个过程。我想在脚本中添加用户输入,该输入将保存为变量。
username = input("Please enter username:")
while username not in users:
print("Incorrect Username")
username = input("Please enter username:")
print("Username Accepted")
但是当我使用批处理文件执行 new.py 文件时,如下所示:
cmd /c C:\ProgramData\Anaconda3\condabin\conda.bat run "C:\ProgramData\Anaconda3\python.exe"
"C:\Users\mbeig\Downloads\new.py"
pause
我收到一条错误消息:
Please enter username:
Traceback (most recent call last):
File "C:\Users\mbeig\Downloads\new.py", line 39, in <module>
username = input("Please enter username:")
EOFError: EOF when reading a line
我希望用户在命令行中输入一个输入,该输入可以用作脚本中的变量。 谢谢!
最佳答案
重新安排程序的逻辑:
users = ['batman', 'robin', 'superman']
while True:
username = input("Please enter username:")
if username in users:
break
else:
print("Incorrect username")
关于python - 使用批处理文件在 python 中获取用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63291201/