wow! (generators) - suggestion (yield saved)

Roman Suzi rnd at
Sun Aug 5 16:01:42 CEST 2001

On Sun, 5 Aug 2001, Ken Seehof wrote:

>From: "Roman Suzi" <rnd at>

>> What do you think?
>> Sincerely yours, Roman Suzi
>This is python, not perl.  Readability therefore has priority over terse
>obfuscation.  I definitely prefer 'yield' over '*'.

'cause I have problems typing 'yiled\h\h\held' ;-)
Seriously, yield is as fundamental as '%' in formatting string
role. There is nothing wrong using '*' instead of yild --
readability doesn't suffer.

>The only argument I can think of in favor of '*' is that it avoids
>introducing a keyword,

I wonder if anybody used yeild as a keyword...

>and therefore is more backward compatible.  Since I don't
>think I have any legacy code with 'yield' in it (knocking on wood), I will
>gladly accept a new keyword to avoid perlization of the python language.

I equally fear it's COBOLization...

>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

Except for long table you get far too many concatenations.
(Well, calendar is not that long).

>Unless, of course you are trying to sell python to a sceptical client
>who, you happen to know, loves generators. :-)
>BTW, nice calendar format.

"Red" days are missing, though...
I also have a lambda-version I wrote long time ago

import sys, re, string
from calendar import *

t="Python Calendar"


if b==1:
  assert 0<m<13 and 0<y<3000
  t="%s for %s, %i"%(t,month_name[m],y)
  def jm(f,l): return string.join(map(f,l))
  b=ta%jm(lambda(x):tr%jm(lambda(x):td%[" ",x][x!=0],x),c)
  b="Oh! Bad values given!"

print """Content-Type: text/html

<div align=center><h1>%(t)s</h1>
<form action="/cgi-bin/pycal.cgi" method="post">
Please, enter data:<br>
Month: <input type="text" name="Month"><br>
Year: <input type="text" name="Year"><br>
<input type="submit" value="Show calendar">

(It was so formatted to beat Perl program doing the same ;-)

Sincerely yours, Roman Suzi
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at _/
_/ Sunday, August 05, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "By all means, let's not confuse ourselves with the facts!" _/

More information about the Python-list mailing list