Simple textual calendar

Tim Chase python.list at tim.thechases.com
Mon Nov 3 10:17:25 EST 2008


> Yes, I saw the calendar module, but, as I said, this isn't
> homework or something like that. It is an example which I've
> setted myself to try to solve to see how it would go. Calendar
> just gives me the solution :-(

Part of the answer to a problem is knowing when not to duplicate 
effort that's already been exerted & tested... :)

However, yes, several of my mini apps have wanted to print 
decorated calendars on the command-line so I've had to rehash 
this logic.  The code in the calendar.py can be instructive, and 
it's not to complex to use the "calendar.monthcalendar(year, 
month)" function to draw these calendars:

   from calendar import monthcalendar, month_name
   year = 2008
   for month in range(1,13):
     print year, month_name[month]
     for i,week in enumerate(monthcalendar(year, month)):
       print "Week %i" % (i+1),
       for day in week:
         print " %02i" % day,
       print

(adjust for special handling of "day=0")

-tkc













More information about the Python-list mailing list