AttributeError: 'datetime' module has no attribute 'strptime'
Here is my
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
And when I'm trying to run the
tr = Transaction('AAPL', 600, '2013-10-25') print tr.date
I'm getting the following error:
self.date = datetime.strptime(self.d, "%Y-%m-%d") AttributeError: 'module' object has no attribute 'strptime'
How can I fix that?
If I had to guess, you did this:
at the top of your code. This means that you have to do this:
to access the
strptime method. Or, you could change the import statement to this:
from datetime import datetime
and access it as you are.
#module class method datetime.datetime.strptime(date, "%Y-%m-%d")
★ Back to homepage or read more recommendations: