0

Here is the code i'm a trying. But Idle gives an Attribute Error. Although calendar is a module in python standard library.

AttributeError: 'module' object has no attribute 'monthcalendar'

The Code:

def main():
   today = datetime.datetime.date(datetime.datetime.now())
   current = re.split('-', str(today))
   current_no = int(current[1])
   current_month = year[current_no-1]
   current_day = int(re.sub('\A0', '', current[2]))
   current_yr = int(current[0])

   print '<h1> %s %s </h1 >' %(current_month, current_yr)

   month = calendar.monthcalendar(current_yr, current_no) 
3
  • Please show the whole code. Commented Dec 27, 2013 at 17:59
  • 2
    Your file wouldn't be called calendar.py by any chance, would it? Commented Dec 27, 2013 at 18:13
  • 1
    What does print calendar.__file__ show is the module filename? Commented Dec 27, 2013 at 18:14

2 Answers 2

1

The module datetime does of course have an attribute monthcalendar. The only reason I can see for this error is if your file is name "Calendar.py"

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

Comments

0

Yes. Initially I save it as calendar.py and it displayed the error message, eventually got it fixed by changing the file name.

1 Comment

There's no point in replying to a comment with an answer that comes out the same as one that was posted years ago.

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.