雷伊吉尔

导航

python学习

#! /usr/bin/python
# coding=utf-8

import calendar


"""
返回的某个月的日历
返回类型是字符串型
"""
cal = calendar.month(2011, 11)

"""
返回一年的日历
"""
cal = calendar.calendar(2011)

cal = calendar.HTMLCalendar(calendar.MONDAY)
"""
打印出一个月日历
"""
cal.formatmonth(2011, 11)
"""
打印出一年的日历
formatyearpage将生成完整的页面代码
"""
print cal.formatyear(2011)
cal.formatyearpage(2011)

"""
默认每周的第一天是星期一,这里修改成星期天
"""
calendar.setfirstweekday(calendar.SUNDAY)

  

将源文件命名为了calendar

在命令行执行的时候报错

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

原因是

PYTHON文件名不能和模块名冲突。

将源文件重命名重命名后还是失败。

新的错误

ImportError: cannot import name 'itemgetter'

原因是源文件所在目录下还有个源文件被我命名为了operator.py

将这个文件名修改后,执行成功

 

posted on 2016-01-13 13:54  雷伊吉尔  阅读(503)  评论(0编辑  收藏  举报