更清晰的错误信息

版本新特性 / Python 3.13

# 注意:下面的内容都需要 Python 3.13 或更新版本。
# 示例运行环境是 Python 3.12,其中还没有这些功能。

import random

# *** 以前 ***
# 过去,自己的文件如果与标准库模块同名,就会遮蔽该模块,
# 而报错信息只说缺少该属性:
#
#   AttributeError: module 'random' has no attribute 'randint'
#
# 原因,也就是脚本旁边自己的 random.py,只能靠猜。
# 回溯只用一种颜色打印,所以在很长的调用链中,
# 真正出错的那一行并不醒目

# *** 在 3.13 版本中 ***
# 报错信息会点明该文件,并说明该怎么处理:
#
#   AttributeError: module 'random' has no attribute 'randint'
#   (consider renaming '/home/me/random.py' since it has the same name as
#    the standard library module named 'random' and prevents importing
#    that standard library module)
#
# 这样的文件引发的导入错误也会得到同样的说明,
# 回溯默认带颜色:出错位置和消息会被突出显示,
# 这在很长的调用链中最有用

print(random.randint(1, 5))