TypeError: 'module' object is not callable - using datetime
Solution 1:
It worked for me, try to not create your own time() method, I renamed it to "my_time()".
The time module defines a lot of functions so, or you just "import time" or you need to specify each function you wanna import like "from time import sleep"
from datetime import datetime
from time import time, sleep
import random
import sys
def questions():
print ('Some things you can ask me:')
sleep(1)
print ('• What day is today? (qdh)')
sleep(1)
print ('• What time is it? (qhs)')
sleep(1)
print ('• I want to play a game! (qjj)')
sleep(1)
print ('• How many days till my birthday? (qda)')
sleep(1)
questionsAnswer = input()
if questionsAnswer == 'qdh':
day()
elif questionsAnswer == 'qhs':
my_time()
elif questionsAnswer == 'qjj':
my_game()
else:
my_birthday()
def day():
sleep(1)
nowDay = datetime.now()
print ('Today is %s/%s/%s' % (nowDay.day,nowDay.month,nowDay.year))
sleep(2)
dayAnswer = input('Want to know what time it is? "Y" for yes and "N" for no: ').lower()
if dayAnswer == 'n':
questions()
else:
my_time()
def my_time():
sleep(1)
nowTime = datetime.now()
print ('Right now it\'s %s hours, %s minutes and %s seconds.' % (nowTime.hour, nowTime.minute, nowTime.second))
sleep(5)
questions()
def my_game():
pass
def my_birthday():
pass
#def start():
name = input('Hi. What is your name? ')
print ('Nice to meet you, ' + str(name) + '.')
sleep(1)
print ('How old are you?')
age = input()
sleep(1)
print (age + '! Cool.')
sleep(2)
questions()
Solution 2:
In your command
nowTime = datetime.now()
datetime
is the module which has no method now()
.
You probably wanted
nowTime = datetime.datetime.now()
where the first datetime
is the module
, and the second one is the class
in it - with the classmethod now()
which creates an object
with current local date and time.
Solution 3:
Replace your import time
to from time import time
.