1. Home
  2. Computing & Technology
  3. Python

How To Create A HTML Calendar In Python Dynamically

From Al Lukaszewski, for About.com

2 of 10

Preparing the Months of the Year

In our calendar, it would be nice to have a header for the calendar that reads something like "A Python-Generated Calendar For..." and have the current month and year. In order to do this, we need to get the month and year from the system. This functionality is something that calendar provides, Python can retrieve the month and year. But we still have a problem. As all system dates are numeric and do not contain unabbreviated or non-numeric forms of the months, we need a list of those months. Enter the list year.

year = ['January',
     'February',
     'March',
     'April',
     'May',
     'June',
     'July',
     'August',
     'September',
     'October',
     'November',
     'December']
Now when we get the number of a month, we can access that number (minus one) in the list and get the full month name.

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. Python and HTML - HTML Calendars in Python - Preparing the Months of the Year

©2009 About.com, a part of The New York Times Company.

All rights reserved.