[Tutor] A year's calendar to a text file?

Dick Moores rdm at rcblue.com
Sun Jul 4 05:48:55 EDT 2004

I've got it, thanks to both Alan Gauld and Lloyd Kvam:

I found this function in the calendar module:

calendar( year[, w[, l[c]]])

Returns a 3-column calendar for an entire year as a multi-line string. 
Optional parameters w, l, and c are for date column width, lines per 
week, and number of spaces between month columns, respectively. Depends 
on the first weekday as set by setfirstweekday(). The earliest year for 
which a calendar can be generated is platform-dependent. New in version 2.0.

import calendar

calendar.setfirstweekday(6) #sets first day of week to Sunday
inp = calendar.calendar(2005)

outp = file("c2005.txt","w")

for line in inp:


print "Year 2005 calendar created as c2005.txt"

Thank you, tutors!

Dick Moores

More information about the Tutor mailing list