开发者社区> 问答> 正文

遇到 global name ‘datetime’ is not def 怎么解决?python报错

遇到 global name ‘datetime’ is not def 怎么解决?python报错

在编写样例代码时出现这种问题。这种情况应该如何解决和避免那?

NameError: global name ‘datetime’ is not defined

原因是什么,为什么会发生异常,以及下面到底发生了什么。如果有人能帮忙?提前谢谢

展开
收起
爱吃鱼的程序员 2020-05-27 13:32:51 872 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    这个问题是我在调用函数time.time()用来计算时间损耗时,使用的函数时报错的,具体解决方案很简单,只要在代码开头加上import time这句把time库文件加进来就好了。

    2020-05-27 15:59:34
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载