combining commands:

s713221 at student.gu.edu.au s713221 at student.gu.edu.au
Tue May 29 05:12:05 EDT 2001


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] )

We'd need to know what c was to begin with, but if you're desperate for
one line, have you tried this to see if it works?

c.execute( "SELECT COUNT(*) from CONCENTRIC" ); print(c.fetchone()[0])

Inside the interpreter, this is equivalent to:

c.execute( "SELECT COUNT(*) from CONCENTRIC" )
print(c.fetchone()[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 called c.execute and this returned some object with a function
fetchone and you called that, you'd be able to squish this down into:

print(c.execute('blablabla').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
punishment :).

Joal Heagney/AncientHart



More information about the Python-list mailing list