AttributeError: 'datetime' module has no attribute 'strptime'

Michael

Here is my Transaction class:

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 date function:

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?

user2555451

If I had to guess, you did this:

import datetime

at the top of your code. This means that you have to do this:

datetime.datetime.strptime(date, "%Y-%m-%d")

to access the strptime method. Or, you could change the import statement to this:

from datetime import datetime

and access it as you are.

The people who made the datetime module also named their class datetime:

#module  class    method
datetime.datetime.strptime(date, "%Y-%m-%d")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AttributeError: 'module' object has no attribute

From Dev

AttributeError: 'module' object has no attribute

From Dev

AttributeError: 'module' object has no attribute

From Dev

AttributeError: 'DataFrame' object has no attribute 'to_datetime'

From Dev

AttributeError: 'str' object has no attribute 'to_datetime'

From Dev

'module' object has no attribute '_strptime' with several threads Python

From Dev

AttributeError:'module' object has no attribute 'call' :Python

From Dev

AttributeError: 'module' object has no attribute 'tk'

From Dev

AttributeError: 'module' object has no attribute 'cache'

From Java

AttributeError: 'module' object has no attribute 'tests'

From Dev

AttributeError: 'module' object has no attribute 'TestCase'

From Dev

AttributeError: 'module' object has no attribute 'version'

From Dev

Mtaplotlib AttributeError: 'module' object has no attribute 'pyplot'

From Dev

AttributeError: 'module' object has no attribute 'plotting'

From Java

AttributeError: 'module' object has no attribute 'request'

From Java

tensorflow:AttributeError: 'module' object has no attribute 'mul'

From Java

AttributeError: 'module' object has no attribute 'urlretrieve'

From Dev

AttributeError: 'module' object has no attribute 'grd'

From Java

AttributeError: module 'importlib' has no attribute 'util'

From Dev

AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'

From Dev

AttributeError: 'module' object has no attribute 'scandir'

From Dev

AttributeError: 'module' object has no attribute 'SFrame'

From Dev

Pylint AttributeError: 'module' object has no attribute 'append'

From Dev

Inheritance AttributeError: 'module' object has no attribute

From Dev

AttributeError: 'module' object has no attribute 'ORB'

From Dev

AttributeError: 'module' object has no attribute 'utcnow'

From Dev

AttributeError: "'module' object has no attribute 'ARRAY'"

From Dev

AttributeError: 'module' object has no attribute 'div'

From Dev

Python AttributeError: 'module' object has no attribute 'atoi'

Related Related

  1. 1

    AttributeError: 'module' object has no attribute

  2. 2

    AttributeError: 'module' object has no attribute

  3. 3

    AttributeError: 'module' object has no attribute

  4. 4

    AttributeError: 'DataFrame' object has no attribute 'to_datetime'

  5. 5

    AttributeError: 'str' object has no attribute 'to_datetime'

  6. 6

    'module' object has no attribute '_strptime' with several threads Python

  7. 7

    AttributeError:'module' object has no attribute 'call' :Python

  8. 8

    AttributeError: 'module' object has no attribute 'tk'

  9. 9

    AttributeError: 'module' object has no attribute 'cache'

  10. 10

    AttributeError: 'module' object has no attribute 'tests'

  11. 11

    AttributeError: 'module' object has no attribute 'TestCase'

  12. 12

    AttributeError: 'module' object has no attribute 'version'

  13. 13

    Mtaplotlib AttributeError: 'module' object has no attribute 'pyplot'

  14. 14

    AttributeError: 'module' object has no attribute 'plotting'

  15. 15

    AttributeError: 'module' object has no attribute 'request'

  16. 16

    tensorflow:AttributeError: 'module' object has no attribute 'mul'

  17. 17

    AttributeError: 'module' object has no attribute 'urlretrieve'

  18. 18

    AttributeError: 'module' object has no attribute 'grd'

  19. 19

    AttributeError: module 'importlib' has no attribute 'util'

  20. 20

    AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'

  21. 21

    AttributeError: 'module' object has no attribute 'scandir'

  22. 22

    AttributeError: 'module' object has no attribute 'SFrame'

  23. 23

    Pylint AttributeError: 'module' object has no attribute 'append'

  24. 24

    Inheritance AttributeError: 'module' object has no attribute

  25. 25

    AttributeError: 'module' object has no attribute 'ORB'

  26. 26

    AttributeError: 'module' object has no attribute 'utcnow'

  27. 27

    AttributeError: "'module' object has no attribute 'ARRAY'"

  28. 28

    AttributeError: 'module' object has no attribute 'div'

  29. 29

    Python AttributeError: 'module' object has no attribute 'atoi'

HotTag

Archive