相关疑难解决方法(0)

AttributeError:'datetime'模块没有属性'strptime'

这是我的Transaction班级:

class Transaction(object):
    def __init__(self, company, num, price, date, is_buy):
        self.company = company
        self.num = num
        self.price = price
        self.date = datetime.strptime(date, "%Y-%m-%d")
        self.is_buy = is_buy
Run Code Online (Sandbox Code Playgroud)

当我试图运行该date功能时:

tr = Transaction('AAPL', 600, '2013-10-25')
print tr.date
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

   self.date = datetime.strptime(self.d, "%Y-%m-%d")
 AttributeError: 'module' object has no attribute 'strptime'
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

python class python-2.7

127
推荐指数
3
解决办法
16万
查看次数

标签 统计

class ×1

python ×1

python-2.7 ×1