Add elements properly to a ListStore in python
<p>I have a textfile with the current data:</p>

<pre><code>Firefox 2002 C++
Eclipse 2004 Java 
Pitivi 2004 Python
Netbeans 1996 Java
Chrome 2008 C++
Filezilla 2001 C++
Bazaar 2005 Python
Git 2005 C
Linux Kernel 1991 C
GCC 1987 C
Frostwire 2004 Java
</code></pre>

<p>I want to read it from my python program and add it to a ListStore to have something like this</p>

<p><a href="http://i.stack.imgur.com/fqnvM.png" rel="nofollow">http://i.stack.imgur.com/fqnvM.png</a></p>

<p>This is my code:</p>

<pre><code>import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

filename = 'data.txt'
with open(filename) as f:
    data = f.readlines()

class TreeViewFilterWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Treeview Filter Demo")
        self.grid = Gtk.Grid()
        self.grid.set_column_homogeneous(True)
        self.grid.set_row_homogeneous(True)
        self.add(self.grid)
        self.software_liststore = Gtk.ListStore(str, str, str)
        self.software_liststore.append(data[0].split())
        self.software_liststore.append(data[10].split())
        i=0
        while (i&lt;(len(data))):
            print(data[i].split())
            self.software_liststore.append(data[i].split())
            i=i+1

        self.treeview = Gtk.TreeView(model=self.software_liststore)
        for i, column_title in enumerate(["Software", "Release Year", "Programming Language"]):
            renderer = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn(column_title, renderer, text=i)
            self.treeview.append_column(column)

        self.scrollable_treelist = Gtk.ScrolledWindow()
        self.scrollable_treelist.set_vexpand(True)
        self.grid.attach(self.scrollable_treelist, 0, 0, 8, 10)
        self.scrollable_treelist.add(self.treeview)
        self.show_all()

win = TreeViewFilterWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
</code></pre>

<p>The problem is that there is no problem doing this:</p>

<pre><code>self.software_liststore.append(data[0].split())
self.software_liststore.append(data[10].split())
</code></pre>

<p>But when I try to use the while loop to insert data, it says:</p>

<pre><code>Traceback (most recent call last):
    File "tut20.py", line 83, in &lt;module&gt;
    win = TreeViewFilterWindow()
File "tut20.py", line 68, in __init__
self.software_liststore.append(data[i].split())
File "/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py", line 956, in append
return self._do_insert(-1, row)
File "/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py", line 947, in _do_insert
row, columns = self._convert_row(row)
File "/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py", line 849, in _convert_row
raise ValueError('row sequence has the incorrect number of elements')
</code></pre>

<p>ValueError: row sequence has the incorrect number of elements</p>

<p>What am I doing wrong?</p>

<p>Ok, line 9 in data.txt is:</p>

<pre><code>Linux Kernel 1991 C
</code></pre>

<p>which contains 4 elements. Try:</p>

<pre><code>Linux_Kernel 1991 C
</code></pre>

<p>or simply:</p>

<pre><code>Linux 1991 C
</code></pre>

python gtk pygobject