简体   繁体   中英

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

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) 

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM