[Baypiggies] Discussion for newbies/beginner night talks

Dennis Reinhardt DennisR at dair.com
Sat Feb 10 02:31:39 CET 2007


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

Dennis
  ---------------------------------
| Dennis    | DennisR at dair.com    |
| Reinhardt | http://www.dair.com |
  ---------------------------------



More information about the Baypiggies mailing list