First off, why are you using an array?  Not that it's bad or anything,
but how does it help you where a simple list would not?

Second, what would be nice is if liststore.insert would take an
interable.  Baring that you could simplify a little like this:

keys = ['v1', 'v1', ..., 'vn']
for d in data:
    selt.liststore.insert(0, tuple(d[k] for k in keys))

whether it is worth it or not depends on how many keys you have.

2010/7/12 Pietro Battiston <m...@pietrobattiston.it>:
> Il giorno lun, 12/07/2010 alle 17.48 +0200, Cornelius Kölbel ha scritto:
>> Dear list,
>>
>> I got an array of dictionaries, that I want to add to a GTKListStore,
>> that is displayed an a treeview.
>>
>> This is very slow. I already replaced the liststore.append by
>> liststore.insert, which is much much faster.
>> But still, filling the 10.000 values takes about 50 seconds.
>>
>> Is there any cool mapping function, to push the array to the liststore?
>> I used a for loop to iterate over the array...
>> I also tried while an to pop the array elements...
>>
>> It is something like this:
>>
>> data: array of dictionaries
>>
>> data = array( { 'v1' : 'something', 'v2': 'something else' } ,
>>               { 'v1' : 'another',   'v2': 'something completely diff' }
>>               )
>>
>>
>> for d in data:
>>    self.liststore.insert( 0, ( d.get("v1"), d.get("v2") ....))
>>
>>
>> ...is there a better way than doing a for loop?
>> ...or a way to not have to interate over the 10.000 dicts?
>>
>> ...or is there a cool reading on performance tuning pyton?
>
>
>
> I really don't know, but... already read
> http://faq.pygtk.org/index.py?req=show&file=faq13.043.htp
> ?
>
> Pietro
>
> _______________________________________________
> pygtk mailing list   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/



-- 
Gerald Britton
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to