AttributeError:type object' datetime.datetime'没有属性' datetime'

时间:2016-11-17 02:41:44

标签: python datetime

我想为变量指定text = 'I miss Wonderland #feeling sad @omg' prefix = ('#','@') words = text.split() # Split the text into a list of its individual words. # Join only those words that don't start with prefix print(' '.join([word for word in words if not word.startswith(prefix)])) ,但我遇到了这个错误。我该如何解决?

datetime.datetime
  

AttributeError:type object' datetime.datetime'没有属性' datetime'

1 个答案:

答案 0 :(得分:1)

在不更改代码的情况下,您只需将import语句更改为:

import datetime

datetime模块中,还有一个名为datetime的对象。您当前的代码正在将datetime对象导入主命名空间。因此,对象类存在于主命名空间中,就像您编写的那样:

class datetime(object):
    ...