2

I'm very new to programming. When i enter the following code into the IDLE3 shell it works fine. When I save it and run it as a module or through the Terminal it returns the following error:

File "/home/pi/Python_Programs/calendar.py", line 4, in calendar.prmonth(2016, i) AttributeError: 'module' object has no attribute 'prmonth'

Here is my code:

import calendar

for i in range(1, 13):
    calendar.prmonth(2016, i)

Please tell me what I am doing wrong?

miradulo
  • 28,857
  • 6
  • 80
  • 93
Ernie Ong
  • 21
  • 1

1 Answers1

2

This is because you named your module calendar.py - Python is attempting to load prmonth from your own module, not from the actual calendar module - you have effectively shadowed it.

Simply name your module something else such that prmonth is accessed from the actual calendar module.

miradulo
  • 28,857
  • 6
  • 80
  • 93