1. Technology

How To Create A HTML Calendar In Python Dynamically


9 of 10

The 'for' Loop Examined

After this range has been started, the dates of the week are culled from month according to the value of the counter and assigned to week. Then, a tabular row is created to hold the calendar dates.

A for loop then walks through the days of the week so they can be analyzed. The calendar module prints a '0' for every date in the table that does not have a valid value. A blank value would work better for our purposes so we print the bookends of tabular data without a value for those dates.

Next, if the day is the current one, we should highlight it somehow. Based on the td class today, the CSS of this page will cause the current date to be rendered against a dark background instead of the light background of the other dates.

Finally, if the date is a valid value and is not the current date, it is printed as tabular data. The exact color combinations for these are held in the CSS style preamble.

The last line of the first for loop closes the row. With the calendar printed our task is finished and we can close the HTML document.

 print "</tbody></table></body></html>" 

Related Video
Create Tables in HTML
Using PHP With HTML
  1. About.com
  2. Technology
  3. Python
  4. Web Development
  5. Python and HTML - HTML Calendars in Python - the 'for' Loop Examined

©2014 About.com. All rights reserved.