python calendar.HTMLCalendar

前端 未结 5 1111
面向向阳花
面向向阳花 2021-02-02 04:10

I think I want to use pythons built in calendar module to create an HTML calendar with data. I say I think because I\'ll probably think of a better way, but right now it\'s a l

5条回答
  •  不思量自难忘°
    2021-02-02 04:40

    It's hard to say without knowing exactly what you're trying to accomplish, but here's one idea.

    Instead of printing myCal.formatmonth(2009, 7), why don't you assign it to a string. Then you could manipulate it, perhaps with a regex.

    Here's a really bad example:

    import calendar
    import re
    
    myCal = calendar.HTMLCalendar(calendar.SUNDAY)
    myStr = myCal.formatmonth(2009, 7)
    
    re.sub('28', '28
    [My Data]', myStr) print myStr

    It does what you want, but it's pretty ugly.

提交回复
热议问题