On Sat, Nov 27, 2010 at 08:40:46PM -0600, alex goretoy wrote: > Currently I am having to do this in my application to create dynamic > treestore; is the a better way to do this? > > def get_treestore(n): > if n == 0: > treestore = gtk.TreeStore(str); > elif n == 1: > treestore = gtk.TreeStore(str); > elif n == 2: > treestore = gtk.TreeStore(str, str); > elif n == 3: > treestore = gtk.TreeStore(str, str, str); > elif n == 4: > treestore = gtk.TreeStore(str, str, str, str); > else: > treestore = gtk.TreeStore(str); > > return treestore
shorter but not prettier: def get_treestore(n): if n in range(1, 5): return gtk.TreeStore(*((str,) * n)) return gtk.TreeStore(str) but you could make some assertions about the parameter passed to `get_treestore`, for example you could assert that `n` has always the right value. in that case the function became: def get_treestore(n=1): return gtk.TreeStore(*((str,) * n)) m. -- Lo punite del fatto che la sua infanzia ha strisciato sul suolo senza stelo e senza tutore; gli imputate come un misfatto l'isolamento in cui lo avete lasciato; della sua sventura fate il suo delitto! Nessuno gli ha insegnato a sapere ciĆ² che faceva: quest'uomo ignora. La sua colpa appartiene al suo destino, non a lui. Voi colpite un innocente. -- Victor Hugo _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/