Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix Python TypeError: 'datetime.datetime' object is not callable?

Trying to assign the datetime.datetime.now() value to the self.startDate variable, but getting the error:

TypeError: 'datetime.datetime' object is not callable

!/usr/bin/python3

import datetime
import os
 
class TradingSystem:
    def __init__(self):
        self.startDate = datetime.datetime.now()

ts = TradingSystem()
print("Started trading system, date: {}".format(ts.startDate()))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try with:

self.startDate = datetime.datetime.now

The problem is that you are already calling the function within your definition and then you’re calling it again.

If what you want is to set the start date at the time of instantiation, let the first part as it was (as you posted it) and try:

print("Started trading system, date: {}".format(ts.startDate))

The first option will always print the current date and time, the former will print the date and time of instantiation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading