python日历函数_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()
本回答由提問者推薦
已贊過
已踩過<
你對這個回答的評價是?
評論
收起
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的python日历函数_python 怎么定义一个函数,输出日历的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pythonscrapy爬虫_零基础写p
- 下一篇: zookeeper 创建临时顺序节点_Z