python - 不明白为什么这段代码会引发 EOF 错误
问题描述
我正在尝试在 Windows 10 上创建一个循环遍历 Unicode 字符的 Python 3 程序,但在最后一个空行上,它的错误为
SyntaxError: unexpected EOF while parsing
我试着把 aprint("Done!")
放在最后,但那是
IndentationError: unexpected unindent
.
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
这是代码的最后一行(空白处)。
解决方案
您需要except
为每个try
.
推荐阅读
- php - Laravel:419 会话在登录时过期,已经包含 CSRF 令牌和帖子
- bash - 我可以手动逐步执行bash,但不能在脚本中执行?
- mysql - 如何在 JOIN 表中使用 SQL CASE & COUNT
- python - 在 PCA 中使用超过 2 台 PC
- spring - 如何为Angular中的某些角色动态分配组件/字段权限?
- c# - 如何使用密钥从 KeyVault 获取凭据?
- azure-active-directory - Azure AD 和 Azure B2c
- superscript - 带有draw_label的ggplo2中的数学/上标注释
- javascript - Angular 事件窗口:滚动不触发(高级布局)
- javascript - 在循环 undefiend 中将数据保存到 mongoDB