[Python-ideas] explicitation lines in python ?

Chris Rebert pyideas at rebertia.com
Sun Jun 27 09:45:47 CEST 2010

On Sun, Jun 27, 2010 at 12:00 AM, Daniel DELAY <danieldelay at gmail.com> wrote:
> Le 26/06/2010 05:26, Chris Rebert a écrit :
>> What do you mean, you can put them right next to each other, and even
>> better, give the expression a meaningful name:
>> def line2html(line):
>>     return ''.join( '<td>{}</td>'.format(cell) for cell in line)
>> htmltable = ''.join( '<tr>{}</tr>'.format(line2html(line)) for line in
>> table)
> Yes that's a solution if this piece of code is run only once.
> But if this piece of code is in a function (or a loop), your function
> line2html will be redefined for each function call (or iteration), wich is
> something I usually try to avoid.

Yes, but Premature Optimization is The Root of All Evil, and you can
always define line2html() at the module level; this trades distance
for speed, but if you chose a good descriptive name, it should still
be plenty clear.

Again, "where" clauses are certainly an intriguing idea.

More information about the Python-ideas mailing list