[Baypiggies] Discussion for newbies/beginner night talks
Paul McNett
p at ulmcnett.com
Sat Feb 10 05:26:27 CET 2007
Dennis Reinhardt wrote:
> At 05:05 PM 2/9/2007, Paul McNett wrote:
>> Dennis Reinhardt wrote:
>> Take this example:
>>
>> class MyBizobj(...):
>> def getCustomerInfo(self, cust_id):
>> sql = """
>> select customers.name as name,
>> sum(invoices.amount) as amount_total,
>> blah as blah
>> from customers
>> left join invoices
>> on invoices.cust_id = customers.id
>> where customers.id = ?"""
>> self.cur.execute(sql, (cust_id,))
>
> To preserve SQL *and* Python structuring, I would write this as:
>
> class MyBizobj(...):
> def getCustomerInfo(self, cust_id):
> sql = ""
> sql += "select customers.name as name,\r\n"
> sql += " sum(invoices.amount) as amount_total,\r\n"
> sql += " blah as blah\r\n"
> sql += " from customers\r\n"
> sql += " left join invoices\r\n"
> sql += " on invoices.cust_id = customers.id\r\n"
> sql += " where customers.id = ?\r\n"
> self.cur.execute(sql, (cust_id,))
Yuck! :) I guess it's good that Python lets me write it how I want to,
and you write it how you want to!
--
pkm ~ http://paulmcnett.com
More information about the Baypiggies
mailing list