wow! (generators) - suggestion (yield saved)

Neil Schemenauer nas at python.ca
Sun Aug 5 13:44:55 EDT 2001


Ken Seehof wrote:
> While your use of generators is clever, I'm not sure what, if anything
> generators are actually buying you here.
> 
> What's wrong with:
> 
> import calendar, string
> def calt(year, month):
>     month_cal = calendar.monthcalendar(year, month)
>     scal = ''
>     scal += "<B>%s.%s</B>" % (month, year)
>     scal += "<TABLE BORDER=1>"
>     for week in month_cal:
>       scal += "\n<TR>"
>       for day in week:
>         scal += "<TD>%s</TD>" % (day or " ")
>       scal += "</TR>"
>     scal += "</TABLE>"
>     return scal

I like PTL for this sort of thing:

 import calendar, string
 def calt(year, month):
     month_cal = calendar.monthcalendar(year, month)
     "<B>%s.%s</B>" % (month, year)
     "<TABLE BORDER=1>"
     for week in month_cal:
       "\n<TR>"
       for day in week:
         "<TD>%s</TD>" % (day or " ")
       "</TR>"
     "</TABLE>"

Cheers,

  Neil




More information about the Python-list mailing list