0

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()))

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

look at my edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.