python - AttributeError: 模块 'datetime' 没有属性 'time'

标签 python python-3.x runtime-error attributeerror python-datetime

我正在使用 Python 3.7 并尝试从库中学习 datetime 模块,但我遇到了 AttributeError。代码如下:

import datetime

t = datetime.time(4, 20, 1)

# Let's show the different components
print(t)
print('hour  :', t.hour)
print('minute:', t.minute)
print('second:', t.second)
print('microsecond:', t.microsecond)
print('tzinfo:', t.tzinfo)

作为运行文件,我收到此错误 AttributeError: module 'datetime' has no attribute 'time'

请帮我找出我哪里出错了。谢谢

最佳答案

问题可能是您的 python 文件与 datetime 模块同名,也许您将程序文件命名为 datetime.py

您需要重命名您的程序文件并删除路径中生成的任何最终 .pyc 文件,然后您可以导入正确的日期时间模块。

关于python - AttributeError: 模块 'datetime' 没有属性 'time',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52494633/

相关文章:

runtime-error - 请问我如何添加运行时选项来禁用检查或此警告

Python:当函数检查变量是否> 0时,我的程序将重新启动

Python 字典包含编码值

python - random.choices 中的累积权重

python - 尝试使用 python 脚本获取源时检测到不安全的依赖于完成的目录

Python 类型注解 : Proper way to annotate functions returning library object

spring - spring 错误中验证器的目标无效?

python - 为什么这不会将 jira 转换为已解决?

python - 如何使用fbProphet或其他模型在Python中执行包含多个组的时间序列分析?

python - 将新的 Pandas DataFrame 附加到旧的 Pandas DataFrame 上,而无需对列名进行排序