python 出现 type object 'xxxxx' has no attribute 'xxxx',什么原因

from datetime import datetime
class Asset(object):
    share=0
    buyTime=datetime.strpdatetime('2018-08-18','%Y-%m-%d')
    sellTime=datetime.strpdatetime('2018-08-19','%Y-%m-%d')
    def __init__(self,id,price):
        self.id=id
        self.price=price
    def buy(self,share,time):
        self.share+=share
        self.buyTime=datetime.strptime(time,'%Y-%m-%d')
    def sell(self,share,time):
        self.share-=share
        self.sellTime=datetime.strptime(time,'%Y-%m-%d')
class NonShortableAsset(Asset):
    def sell(self,share,time):
        if self.share>=share:
            self.share-=share
            self.sellTime=datetime.strptime(time,'%Y-%m-%d')
        else:
            print('Not permitted! There are not enough share to sell!')
            print('Current share is ',self.share)
            return
        
Traceback (most recent call last):

  File "", line 2, in 
    class Asset(object):

  File "", line 4, in Asset
    buyTime=datetime.strpdatetime('2018-08-18','%Y-%m-%d')

AttributeError: type object 'datetime.datetime' has no attribute 'strpdatetime'

Traceback (most recent call last):

  File "", line 2, in
    class Asset(object):

  File "", line 4, in Asset
    buyTime=datetime.strpdatetime('2018-08-18','%Y-%m-%d')

AttributeError: type object 'datetime.datetime' has no attribute 'strpdatetime'

你可能感兴趣的:(python学习笔记)