caltext +sunday monday tuesday wednesday thursday friday saturday \ the horizontal line string that separate weeks weekseparator ('+ '+\ the blank rows have ten spaces in between the day separators blankrow (' '|\ get the first date in the month (the datetime module handles all the complicated calendar stuff for us here currentdate datetime date(yearmonth roll back currentdate until it is sunday (weekday(returns for sundaynot while currentdate weekday(! currentdate -datetime timedelta(days= while trueloop over each week in the month caltext +weekseparator daynumberrow is the row with the day number labels daynumberrow ' for in range( ) daynumberlabel str(currentdate dayrjust( daynumberrow +'|daynumberlabel ( currentdate +datetime timedelta(days= go to next day daynumberrow +'|\nadd the vertical line after saturday add the day number row and blank rows to the calendar text caltext +daynumberrow for in range( )(!try changing the to or caltext +blankrow check if we're done with the month if currentdate month !month break add the horizontal line at the very bottom of the calendar caltext +weekseparator return caltext caltext getcalendarfor(yearmonth print(caltextdisplay the calendar save the calendar to text file calendarfilename 'calendar_{} {txtformat(yearmonth with open(calendarfilename' 'as fileobj fileobj write(caltext print('saved to calendarfilenamecalendar maker