[Tutor] A year's calendar to a text file? (original) (raw)

Lloyd Kvam pythonTutor at venix.com
Sat Jul 3 12:19:34 EDT 2004


It looks like prcal (and the other print functions in calendar) use sys.stdout for the output file. There's no real skill to the programming solution. The problem is knowing the name (binding) for the file used in the calendar module. The solution is to assign (bind) your file to the name used in the calendar module. Since sys.stdout is generally the default output file, you will want to bind sys.stdout back to its original file after you are done printing the calendar. try / finally is the python language construct to use to make sure that sys.stdout is restored even if something goes wrong printing the calendar. Also, you need to import sys to be able to reference sys.stdout.

Hopefully this is the information you are looking for with the right level of detail.

On Sat, 2004-07-03 at 05:05, Dick Moores wrote: > I'm just beginning to get into learning the use of file methods. I'm > wondering what the limits are. One I've thought of is, can I write to a > file a year's calendar created using the calendar module? I've got the > trivial script for the calendar: >> """ > # print any year's calendar from 1 C.E. through 9999 C.E. >> import calendar >> calendar.setfirstweekday(6) # sets first day of week to Sunday >> year = int(rawinput("Enter year for which to print calendar ")) >> print "\n\n" > calendar.prcal(year) > """ >> If this is possible, could someone tell me so, and get me headed in the > right direction without giving me the whole solution? >> Thanks, tutors >> Dick Moores >>> _________________________ > Tutor maillist - Tutor at python.org > http://mail.python.org/mailman/listinfo/tutor

Lloyd Kvam Venix Corp. 1 Court Street, Suite 378 Lebanon, NH 03766-1358

voice: 603-653-8139 fax: 801-459-9582



More information about the Tutor mailing list