貌似没有现成的......从别的地方找一个能实现你说的功能的代码,你可以看看:
#encoding:utf8
def w_day(y,m,d):#已知日期求星期
c=y//100
y=int(str(y)[-2:])
w=(y+(y//4)+(c//4)-2*c+(26*(m+1)//10)+d-1)%7 ##蔡勒公式只适合于1582年10月15日之后
return w
def ml(y,m,d=1):#当月有几天
ly=(y%400==0) or (y%4==0 and y%100!=0) and 1 or 0 #闰年=1,平年=0
return (m in (4,6,9,11) and 30 or (m==2 and 28+ly or 31))
def cal(y,m,d): #输出日历
wf=w_day(y,m=1,d=1) #该月的第一天是星期几
mc=[(d==x and ("["+str(x).rjust(2)+"]").center(5) or str(x).rjust(2).center(5)) for x in range(1,ml(y,m)+1)]
mc[:0]=[" "*5]*wf
mc=[(i+1)%7 and j or j+"\n" for i,j in enumerate(mc)]
td=("%s年%s月%s日 星期%s\n" %(y,m,d,("一","二","三","四","五","六","日")[w_day(y,m,d)-1])).center(35)
x="\n Sun Mon Tue Wed Thu Fri Sat\n"
return td+x+"".join(mc)
##################################################################
##################################################################
if __name__ == '__main__':
import datetime
T=datetime.date.today()
print("今天是:\n"+cal(T.year,T.month,T.day))
>>> import time
>>> fun = lambda year, month: list(range(1, 1+time.localtime(time.mktime((year,month+1,1,0,0,0,0,0,0)) - 86400).tm_mday))
>>> fun(2013, 7)
[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]
import datetime
oneday = datetime.timedelta(days=1)
def monthdays(y, m):
dt0 = datetime.datetime(y, m, 1)
return filter(lambda dt: dt.month==m,
map(lambda n: dt0+n*oneday, xrange(32)))
import calendar
print range(calendar.monthrange(year, month)[1]+1)[1:]