0

I am getting the below error when running a script that creates a list of holidays in variable h. I first ran the script on jupyter notebook and it worked fine with no errors, however when I run it as a script it does not work.

I looked at several posts to resolve the issue, but I am specifying what I am importing in the script so not sure why it still does not work.

Error

Traceback (most recent call last):
  File "\\user\config\workspace\ExcelProjects\src\root\nested\scrap.py", line 53, in <module>
h = USBankHolidayCal.holidays(datetime(2016, 1, 1), datetime(2016, 12, 31))
TypeError: 'module' object is not callable  

Code

from pandas.tseries.holiday import Holiday, AbstractHolidayCalendar, nearest_workday, MO, USFederalHolidayCalendar
from pandas.tseries.offsets import DateOffset, CDay
UKdays = []


class UKHoliday(AbstractHolidayCalendar):
rules = [
    Holiday('Boxing Day', month=12, day=26, year=2016,observance=nearest_workday),
    Holiday('Christmas Day', month=12, day=27, year=2016,observance=nearest_workday),
    Holiday('New Years Day', month=1, day=2, observance=nearest_workday),
    Holiday('Good Friday', month=4, day=14, observance=nearest_workday),
    Holiday('Easter Monday', month=4, day=17, observance=nearest_workday),
    Holiday('Early May', month=5, day=1, observance=nearest_workday),
    Holiday('Spring Bank', month=5, day=29, observance=nearest_workday),
    Holiday('Summer Bank', month=8, day=28, observance=nearest_workday),
    Holiday('Christmas Day', month=12, day=25, observance=nearest_workday),
    Holiday('Boxing Day', month=12, day=26, observance=nearest_workday),
]
UKBankHolidayCal = UKHoliday()
h = UKBankHolidayCal.holidays(datetime(2016, 1, 1), datetime(2016, 12, 31))
for x in h:
    UKdays.append(x.date())

Any help greatly appreciated!

3
  • 1
    must depend on the way you import datetime. Commented Dec 21, 2016 at 17:50
  • you are terrific! that was it Commented Dec 21, 2016 at 17:52
  • my pleasure. I tend to avoid the from form as it confuses the editor (completion) and the humans :) I prefer the long forms with full namespace. Commented Dec 21, 2016 at 17:57

1 Answer 1

1

if you do:

import datetime
datetime(2016, 1, 1)

you get

TypeError: 'module' object is not callable

But if you do

from datetime import datetime
datetime(2016, 1, 1)

it works.

So the problem resides in the way you're importing datetime. You have to use the 2nd version in your case, or you're mixing up the module with the object, which share the same name.

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

Comments

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.