Thanks so much for the help Jeff and yes I'm working with Glade 3.16.1 
and Python 3.4.3
Based on your suggestion I got the following test code to work, I'd 
appreciate any comments
on the code. What I'm attempting to do is build tabs on the fly based on 
user choices.

in data/test.py
def buttons():
     return ['Button 0', 'Button 1', 'Button 2', 'Button 3', 'Button 4']

in main.py
     def on_button1_clicked(self, widget):
         self.card = 'test' # based on a user choicenormally
         self.test_grid = self.builder.get_object('test_grid')
         self.card_test = importlib.import_module('data.'+ self.card)
         self.ct_buttons = self.card_test.buttons()
         for index, item in enumerate(self.ct_buttons):
             vars(self)['button'+str(index)] = Gtk.Button(label=item)
         for index, item in enumerate(self.ct_buttons):
             # .attach(child, left, top, width, hieght)
             self.test_grid.attach(getattr(self, 'button%d' % index),0 , 
index, 1, 1)

Thanks
JT



On 7/16/2016 8:26 AM, Jeff Epler wrote:
> In general, you shouldn't use exec() at all.
>
> First and best option, make self.button be a list of buttons, so that
> you can write self.button[index].
>
> You may be working with an object structure you can't control (like
> glade or something), in which case use getattr:
>      self.grid.add(getattr(self, 'button%d' % index))
>
> You could put this getattr behind a method, so that you don't have to
> repeat it at each site where you need to refer to a button by index:
>
>      def button(self, i): return getattr(self, 'button%d' % index)
>      ...
>      def anothermethod(self):
>          self.grid.add(self.button(index))
>
> Jeff
>
> ------------------------------------------------------------------------------
> What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
> patterns at an interface-level. Reveals which users, apps, and protocols are
> consuming the most bandwidth. Provides multi-vendor support for NetFlow,
> J-Flow, sFlow and other flows. Make informed decisions using capacity planning
> reports.http://sdm.link/zohodev2dev
> _______________________________________________
> Emc-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/emc-developers


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to