0

I started learning Python from CodeAcademy, and I realized right away that the course was outdated. I continued the course with VisualStudio open in case I wanted to make sure something didn't change. However, I tried making a very simple program that outputs the date in VisualStudio and it's not doing anything.

from datetime import datetime
now = datetime.now
print(now.second)

When I run this in the VisualStudio environment, it throws the error:

AttributeError: 'builtin_function_or_method' object has no attribute 'second'

When only seconds ago I had done it in CodeAcademy. I have done my fair share of googling and found nobody who has come across the same issue.

3
  • 3
    You need to call the method datetime.now by adding parentheses. now = datetime.now() Commented Feb 19, 2018 at 0:49
  • 2
    Useful shortcut: Paste your code, highlight it, hit Ctrl+k. No need to manually put spaces or backticks. Commented Feb 19, 2018 at 0:51
  • You can refer to the official python document to see the latest usage of each module. Commented Feb 19, 2018 at 1:02

1 Answer 1

2

now is a function (technically a class method) so call it like this: print(now().second)

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

1 Comment

Can always count on Stackoverflow to make me sound stupid

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.