exec function

tertius terti at mighty.co.za
Sat Feb 12 18:02:56 EST 2005


scottmallory at gmail.com wrote:

> I'm a newbie to pthyon and I am creating an app with wxPython.
> I have 7 tables (more on the way... they are feed from a database) that
> need to be formatted in a certain way (DataTable() does this) and I am
> just looking for a cleaner way to pass all of the Grids (grid_1,
> grid_2, etc) through the same function.
> I am currently doing this (ugly, but it works):
> 
> for i in tables.keys():
>     if datadict.has_key(i):
>          t = tables.get(i)
>          d = datadict.get(i)
>          r = rowdata.get(i)
>          exec('self.frame.%s.SetTable(DataTable(d, r[0]), True)' % t)
> 
> 
> It works (slowly) and I have read that exec is very slow and bad
> form...Can any one give me any pointers to clean this mess up?
> 
> frame = a wx.Frame (another file which is imported).
> 
> Thanks,
> Scott
> 
def getUniqueCustomer(self,idcustomer):             #,cols = "*"):
         sql = """select * from customer where idcustomer=%d"""%(idcustomer)
         self.db.sql_exec(sql)
         if self.db.crsr.rowcount == 0:
             return None
         cols = list([i[0] for i in self.db.crsr.description])
         vals = self.db.sql_fetchone()
         return  dict(zip(cols,vals))



More information about the Python-list mailing list