python 怎么定义一个函数,输出日历

如题所述

import re

def command_add(date, event_details, calendar):
'''
Add event_details to the list at calendar[date]
Create date if it was not there

:param date: A string date formatted as "YYYY-MM-DD"
:param event_details: A string describing the event
:param calendars: The calendars database
:return: a string indicating any errors, "" for no errors
'''
try:
p = re.compile(r"\d{4}-\d{2}-\d{2}")
assert p.match(date), "Param date must match YYYY-MM-DD"
assert isinstance(event_details, str), \
"Param event_details must be a string"
if date in calendar:
calendar[date].append(str(event_details))
else:
calendar.update({date: str(event_details)})
except Exception,e:
return str(e)

def main():
calendar = {}
command_add("2015-10-20", "Python class", calendar)
print calendar
command_add("2015-11-01", "go out with friends after test",
calendar)
print calendar

if __name__ == "__main__":
main()
温馨提示:内容为网友见解,仅供参考
第1个回答  2022-06-25
import calendar
import datetime
today = datetime.datetime.today()
print(f"今天日历: {today}", calendar.month(today.year, today.month))
相似回答