analitics

Pages

Showing posts with label calendar. Show all posts
Showing posts with label calendar. Show all posts

Thursday, February 3, 2011

Python - calendar

Two simple example about calendar python module.
Show calendar 04 - 2011 :

>>> import calendar
>>> tc = calendar.TextCalendar(calendar.SUNDAY)
>>> print tc.formatmonth(2011,04)
     April 2011
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

>>>
Show calendar in HTML format :
>>> import calendar
>>> hc = calendar.HTMLCalendar(calendar.SUNDAY)
>>> print hc.formatmonth(2011,04)
;
The result is a HTML table with the calendar.
This is all .

Friday, February 27, 2009

First step ...and some examples

So the first step to use python is how to load module.
This is simple one:

import sys
import math
from math import sin
dir(math)

['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']

Next is two examples with calendar module.

import calendar
time_cal=calendar.TextCalendar(calendar.FRIDAY)
print time_cal.formatmonth(2009,02)
February 2009
Fr Sa Su Mo Tu We Th
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28

If i use this into web page this is the solution:

import calendar
html_cal=calendar.HTMLCalendar(calendar.MONDAY)
print html_cal.formatmonth(2009,02)










February 2009
MonTueWedThuFriSatSun






1
2345678
9101112131415
16171819202122
232425262728