Revision 30e9b072-ccaa-4374-b88b-351ba5dbdec5 - Code Golf Stack Exchange
##Python 2.7 - 152
Unfortunately it fails for [September 1752][1]. Granted, it imports all of the calender functions, but only *uses* 1, and that just returns the start day of the week and the number of days.
from calendar import*
w,l=monthrange(*divmod(input(),100))
print" Mo Tu We Th Fr Sa Su\n"+" "*w+''.join(["%3d"%s+"\n"*((s+w)%7<1)for s in range(1,l+1)])
Relatively standard code, but this is my favourite bit:
"\n"*((s+w)%7<1)
It prints the new line using string multiplication, if the number of the current day and start day of the week is Sunday (e.g. 7) as the boolean is cast to an integer.
This saves a character on the more intuitive `x%7==0` by using `x%7<1` instead.
Test output:
> 198210
Mo Tu We Th Fr Sa Su
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
[1]: http://en.wikipedia.org/wiki/Calendar_%28New_Style%29_Act_1750