"datetime":“模块"对象没有属性“现在" [英] "datetime": 'module' object has no attribute 'now'

查看:36
本文介绍了"datetime":“模块"对象没有属性“现在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用from datetime import datetime方法运行的脚本.第一次运行脚本时,第一次调用datetime.now()会引发错误.如果我再次运行它,它将顺利通过其余部分.

I have a script that I run using the from datetime import datetime method. The first time that I run the script, the first call to datetime.now() throws the error. If I run it again it will sail through the rest without a problem.

这是一个代码段:

from datetime import datetime

tot_time = datetime.now() # It bonks on this line

推荐答案

如果在from datetime import datetime之后执行import *,则可能会用另一个模块中的普通import datetime覆盖from导入.

If you are doing an import * after your from datetime import datetime, you could be overriding your from import with a plain import datetime from another module.

找出是否是名称空间问题的一种方法是执行以下操作: from datetime import datetime as dt.大概不会与另一个dt发生冲突.

One way to find out if it is a namespace issue is to do the following: from datetime import datetime as dt. Presumably, you won't collide with another dt.

这篇关于"datetime":“模块"对象没有属性“现在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆