. Advertisement .
..3..
. Advertisement .
..4..
I don’t know what I’m doing wrong, but I’ve already lost a couple of days struggling with this. Here is my command line:
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
tr = Transaction('AAPL', 600, '2013-10-25')
print tr.date
This returns:
self.date = datetime.strptime(self.d, "%Y-%m-%d")
AttributeError: 'module' object has no attribute 'strptime'
I don’t have any experience with the “attributeerror: module ‘datetime’ has no attribute ‘strptime’.” In this case, how should I change?
The cause: I think this error happens perhaps you did this:
at the beginning of your code.
The solution: To solve this problem, you must perform the following:
to get a hold of the
strptime
method. Alternatively, you might change the import statement into:then use it as you normally would.
Make sure you use the correct call.
strptime
is adatetime.datetime
classmethod, not adatetime
function.Jon Clements mentioned it in the comments. This would bind
datetime
todatetime
and allow you to start your first code work.Look at your import statements to determine which case you are facing in the future.
import datetime
: That’s the module (that is what you have now).from datetime import datetime
: That’s the class.