Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError ('module' object is not callable) using dateutil relativedelta

I'm trying to use dateutil and relativedelta to retrieve the difference between two dates (runwayMonths) but I'm getting TypeError: 'module' object is not callable and can't figure out why.

I assume the issue is with how I'm calling the class and/or module but I can't find a similar example on here or elsewhere that helps me understand what I'm doing wrong.

import datetime
from datetime import timedelta
from dateutil import relativedelta

today = datetime.date.today()
runwayDays = 529
dropDeadDate = today + timedelta(days=runwayDays)
runwayMonths = relativedelta(today,dropDeadDate)

I could understand if I was screwing up the formatting for the parameters for relativedelta as I'm a total noob but the error seems to suggest the issue is with the module or class. Any help would be appreciated!

like image 534
user1469701 Avatar asked Feb 10 '19 02:02

user1469701


1 Answers

dateutil.relativedelta is a module, and the relativedelta() function is inside it.

Try this instead:

from dateutil.relativedelta import relativedelta

like image 65
John Gordon Avatar answered Oct 16 '22 22:10

John Gordon