>>> from datetime import date
>>> daysOfMonth=[31,28,31,30,31,30,31,31,30,31,30,31]

>>> def myCalendar(year,month):
start=date(year,month,1).timetuple().tm_wday
print('{0} year {1} month'.format(year,month).center(56))
print('t'.join('Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split()))
day =daysOfMonth[month-1]
if month==2:
if year%400==0 or (year%4==0 and year%100!=0):
day +=1
result=[' '*8 for i in range(start+1)]
result+=list(map(lambda d:str(d).ljust(8),range(day+1)))
for i,day in enumerate(result):
if i!=0 and i%7==0:
print()
print(day,end='')
print()

>>> def main(year,month=-1):
if type(year)!=int or year<1000 or year>10000:
print('Year error')
return
if type(month)==int:
if month==-1:
for m in range(1,13):
myCalendar(year,m)
elif month in range(1,13):
myCalendar(year,month)
else:
print('Month error')
return
else:
print('Month error')
return

>>> main(2017)
2017 year 1 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday

0 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
2017 year 2 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28
2017 year 3 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
2017 year 4 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
2017 year 5 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
2017 year 6 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
2017 year 7 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
2017 year 8 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
2017 year 9 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
2017 year 10 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday

0 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
2017 year 11 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
2017 year 12 month
SundaytMondaytTuesdaytWednesdaytThursdaytFridaytSaturday
0 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

python_自定日历的更多相关文章

  1. 日历类Calendar

    在早期的JDK版本中,日期(Date)类附有两大功能:(1)允许用年.月.日.时.分.秒来解释日期:(2)允许对表示日期的字符串进行格式化和句法分析.在JDK1.1中提供了类Calendar来完成第一 ...

  2. java util包概述

    util是utiliy的缩写,意为多用途的,工具性质的包这个包中主要存放了:集合类(如ArrayList,HashMap等),随机数产生类,属性文件读取类,定时器类等类.这些类极大方便了Java编程, ...

  3. java.util包详解

    介绍Java的实用工具类库java.util包.在这个包中,Java提供了一些实用的方法和数据结构.本章介绍Java的实用工具类库java.util包.在这个包中,Java提供了一些实用的方法和数据结 ...

  4. python_日历

    >>> import datetime>>> Today=datetime.date.today()>>> Todaydatetime.date( ...

  5. js编写当天简单日历

    之前一直很想用javascript写一个日历,但是因为完全没有好的思路, 所以迟迟没有尝试.最近在网上刚好看到用javascript编写的简单日历的例子,代码量虽然不大, 但是我觉得很好地阐述了js日 ...

  6. SharePoint 2013 日历重叠功能简介

    之前做了一个“SharePoint 2013 日历根据Category显示不同颜色”,然后大家留言说为什么不用SharePoint自带的日历重叠功能,所以自己尝试一下这个功能,和之前的博客进行一下对比 ...

  7. cocos2d-html5版日历组件

    根据一as3版本给改编成成了js版的.as3版本的地址:  http://download.csdn.net/detail/fengye513/2722289 胜利项目做的差不多了,由于项目用的是c+ ...

  8. jquery.fullCalendar官方文档翻译(一款小巧好用的日程管理日历, 可集成Google Calendar)

    1. 使用方式, 引入相关js, css后, $(‘#div_name’).fullCalendar({//options});  接受的是一个option对象 2. 普通属性 2.1. year, ...

  9. C#日历上显示节气、阴阳历节假日信息

    近期在做一个工作日历,想在日历上设置工作日,显示请假.加班等相关信息,显示农历日期信息(包括农历日期.节日 .节气).公历信息(节假期). 不能不说,http://www.cnblogs.com/ho ...

随机推荐

  1. Python学习笔记 - map reduce

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- def f(x): return x * x r = map(f, [1, 2, 3, 4, 5, 6, ...

  2. of这个变态

    英式口语还能听懂,一到美式,连读,爆破,就让人疯掉. 尤其big bang theory, of就是个变态,其读法有,英[əv, əv, v, f] 美[əv, ɑv,əv].但大部分都是/əv/. ...

  3. Linux系统的shell是什么

    shell是用户和Linux操作系统之间的接口.Linux中有多种shell,其中缺省使用的是Bash.本章讲述了shell的工作原理,shell的种类,shell的一般操作及Bash的特性. 什么是 ...

  4. STL算法设计理念 - 二元函数,二元谓词以及在set中的应用

    demo 二元函数对象 #include <iostream> #include <cstdio> #include <vector> #include <a ...

  5. 计算机编码方式详解(Unicode、UTF-8、UTF-16、ASCII)

    整理这篇文章的动机是两个问题: 问题一: 使用Windows记事本的"另存为",可以在GBK.Unicode.Unicode big endian和UTF-8这几种编码方式间相互转 ...

  6. Spring--ClassPathXmlApplicationContext

    public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext { private Resource ...

  7. obj-c中SEL签名和Invocation示例

    参考小示例,代码如下: #import <Foundation/Foundation.h> @interface PlayList:NSObject @property NSMutable ...

  8. Linux下转换文件从GBK到UTF-8

    iconv -f gbk -t utf- source-file -o target-file

  9. jquery-取消冒泡

    1.通过返回false来取消默认的行为并阻止事件起泡. jQuery 代码: $("form").bind( "submit", function() { re ...

  10. css3-------:before和:after的作用

    1.:before和:after的作用就是在指定的元素内容(而不是元素本身)之前或者之后插入一个包含content属性指定内容的行内元素,最基本的用法如下: <!doctype html> ...