append to non-existing list

Roy Smith roy at panix.com
Wed Nov 9 08:52:30 EST 2005


In article <mailman.353.1131543337.18701.python-list at python.org>,
 Yves Glodt <y.glodt at sitasoftware.lu> wrote:

> > You mean you want to type "pkcolumns" only once to keep your code short?
> > Would something like this be useful?
> > 
> > pkcolumns = [row.strip() for row in sqlsth]
> 
> I will look into this, maybe it's what I need, thanks!

The list comprehension format described above is handy and compact, and 
there's no reason you shouldn't use it when appropriate.  That being said, 
compactness should not itself be a goal.

Writing clear and easy to understand code is much more important than 
reducing the number of lines.  Sometimes you get both at the same time, but 
not always.



More information about the Python-list mailing list