Newbie Q: modifying SQL statements

Faber J. Fedor faber at linuxnj.com
Fri Jan 11 18:11:41 EST 2008


On 10/01/08 22:53 -0500, Mike Meyer wrote:
> Personally, I think it would be more pythonic to not try and use two
> different APIs to walk the list of jobs (... One Way To Do it):
> 
> def __call__(self, where=None):
>     q = "select * from %s" % (self.name,) + ("" if not where else (" where %s" % where))

Does this '("" if not where...' syntax actually work?  I couldn't get it to
compile and I couldn't find any examples of such syntax (but you can't
expect googling for 'if not' to be too successful). I ended up
changing that line to:

        q = "select * from %s" % (self.name,)
        if where: q += "where %s" %where


>     for r in self.dbc.iterresults()	# I assume it has something like this

I don't think it does, if I read
http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQLdb-3.html
correctly.


-- 
 
Regards,
 
Faber Fedor

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the Python-list mailing list