我试图在 Windows 10 上创建一个循环 Unicode 字符的 Python 3 程序,但在最后一个空行上,出现以下错误
SyntaxError: unexpected EOF while parsing
我尝试在末尾添加 print("Done!")
但那是这样的
缩进错误:意外取消缩进
。
max = int("FFFC",16)
min = 0
for x in range(max + 1):
try:
hex_value = hex(x)
proper = str(hex_value)[2:].upper()
while len(proper) != 4:
proper = "0" + proper
proper = "U+" + str(proper)
print(f"{proper} : {chr(x)}")
错误:
File "unicode.py", line 11
^
SyntaxError: unexpected EOF while parsing
这是代码的最后一行(空白)。
最佳答案
您需要为每个 try
包含一个 except
语句。
关于python - 不明白为什么这段代码会引发 EOF 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56906753/