EnderShot355
EnderShot355

Reputation: 13

Simple Python code not working but not throwing an error in the editor

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.

Upvotes: 0

Views: 51

Answers (1)

AGN Gazer
AGN Gazer

Reputation: 8378

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

Upvotes: 2

Related Questions