python - Python程序在输入换行符后有奇怪的符号?程序在在线编辑器中工作
问题描述
所以我在这里有一个程序:https ://repl.it/@cooperl2/Find-Student-Info-V4-FINAL-STABLE
代码:
import datetime
import sys
def find_info():
first_name = input("What is your first name? ").lower()
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
last_name = input("What is your last name? ").lower()
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
grade = input("What grade are you in? ").lower()
grade = int(grade[0])
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
year = datetime.date.today().year
month = datetime.date.today().month
shift = 1 if datetime.date.today().month < 9 else 0
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
pin = input("What is your lunch pin / ID number? ")
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
grad_year = year + 13 - grade - shift
#this replaces the entire if statement in the V3 -- See V3 for details.
print("Hello there " + first_name+"!")
print("\n")
print("Your username is: " + last_name.lower() + first_name[0].lower() + str(grad_year)[2]+ str(grad_year)[3])
print("Your password is: " + first_name[0].lower() + last_name[0].lower() + pin + "hoh")
print("Your Email Address is: " + last_name.lower() + first_name[0].lower() + str(grad_year)[2]+ str(grad_year)[3] + "@learn.hohschools.org")
find_info()
但是,当我通过双击我的桌面在我的计算机上运行它时,它看起来像附加的图像。并且程序在第三个问题后退出并且没有完成。不知道为什么会这样以及为什么会有奇怪的符号。
解决方案
这些是ANSI 转义序列-\033[F
将光标移回上一行,并\033[K
清除当前行。当您在其中运行程序的终端无法识别这些转义序列时,将出现您注意到的问题。
推荐阅读
- hibernate - 如何删除具有许多双向关系的实体
- javascript - 如何避免在 React 中重复 JSX/HTML 代码?
- python - 一个线程没有在 python 中启动
- for-loop - 使用 FOR /L 循环在批处理文件中根据当前月份循环遍历一年中的月份
- git - How to change author of git commit using ssh keys
- javascript - 从输入字段获取 RAW 值 - javascript/html
- woocommerce - 在 woocommerce 结帐中更改选项值文本
- javascript - 在 javascript (Vuejs) 的 HTML 字符串上添加事件
- html - Perl:如何将 unicode 符号转换为能够在进出数据库并在 HTML 中呈现的东西
- c# - 获取所有像素均为白色的图像行时出现问题