python - Use calendar module function -


i need use 1 of calendar module functions, python renders weird output.

from calendar import calendar cal def calend(year):     print cal.yeardatescalendar(year, width=3) cal(2015) >>> typeerror: unbound method yeardatescalendar() must called calendar instance first argument (got int instance instead) 

ok, lets try

from calendar import calendar cal def calend(year):     y = cal(2015)     print cal.yeardatescalendar(y, width=3) cal(2015) >>> typeerror: yeardatescalendar() takes @ least 2 arguments (2 given) 

what doing wrong? p.s. documentation module seems incomplete.

yeardatescalendar instance method of calendar class, call need first create instance of calendar class, call method on instance, this:

import calendar def calend(year):                            mycalendar = calendar.calendar()     print mycalendar.yeardatescalendar(year, width=3)  

if call method on class without first creating instance unboundlocalerror in first example.

calendar.yeardatescalendar takes integer it's first parameter - in second example passed calendar instance.


Comments