exec function

scottmallory at gmail.com scottmallory at gmail.com
Sat Feb 12 17:03:20 EST 2005


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




More information about the Python-list mailing list