combining commands:

Alex Martelli aleaxit at yahoo.com
Tue May 29 08:53:16 CEST 2001


<s713221 at student.gu.edu.au> wrote in message
news:3B1367E5.3C64ED44 at student.gu.edu.au...
> kasper37 at caffeinedreams.com wrote:
> >
> > is there any way to combine these three commands into 1 line?
> >
> > c.execute( "SELECT COUNT(*) from CONCENTRIC" )
> > temp = c.fetchone()
> > print( temp[0] )
    ...
> Which is IMHO is clearer than the ; syntactic squishyness anycase. You
> won't be able to squish this down any more than that as first you are
> calling c.execute, and then calling c.fetchone, two different methods.

If you've BET with somebody about this, and c.execute returns None,
as is common with functions which have nothing special to return,
the following may win you a beer or thereabouts:

    print c.execute('blabla') or c.fetchone()[0]

> but then the style-police would probably hack into your machine and
> confiscate your python interpreter to rescue it from cruel and unusual

I'm not even gonna GUESS at what the PSU would undoubtedly inflict
on the perpetrator of the or-trick in actual production code...


Alex






More information about the Python-list mailing list