Python help, reading and writing to a txt file
<p>I have posted the relevant part of my code below. Before that are just load functions, which I am pretty sure have no errors.</p>

<p>I am recieving error</p>

<pre><code>IndexError: list index out of range( "namestaj["Naziv"] = deon[1]")
</code></pre>

<p>Does anyone see something out of order?</p>

<pre><code>#load furniture from a txt file
def ucitajNamestaj():
    listaNamestaja = open("namestaj.txt", "r").readlines()
    namestaj = []
    for red in listaNamestaja:
        namestaj.append(stringToNamestaj(red))
    return namestaj

#String to Furniture, dictionary
def stringToNamestaj(red):
    namestaj = {}
    deon = red.strip().split("|")
    namestaj["Sifra"] = deon[0]
    namestaj["Naziv"] = deon[1]
    namestaj["Boja"] = deon[2]
    namestaj["Kolicina"] = int(deon[3])
    namestaj["Cena"] = float(deon[4])
    namestaj["Kategorija"] = deon[5]
    namestaj["Dostupan"] = deon[6]
    return namestaj
</code></pre>

<p>Couple of things first, try always to provide a <a href="http://stackoverflow.com/help/mcve">mcve</a> and make sure you use properly the SO code directives, otherwise your question is unreadable.</p>

<p>Now, probably what's happening is your file has some empty lines and you're not skipping those, try this:</p>

<pre><code>def ucitajNamestaj(): 
    listaNamestaja = open("namestaj.txt", "r").readlines() 
    namestaj = [] 
    for red in listaNamestaja:
        if red.strip() == "":
            continue
        namestaj.append(stringToNamestaj(red)) 
    return namestaj

def stringToNamestaj(red):
    namestaj = {}
    deon = red.strip().split("|")
    namestaj["Sifra"] = deon[0]
    namestaj["Naziv"] = deon[1]
    namestaj["Boja"] = deon[2]
    namestaj["Kolicina"] = int(deon[3])
    namestaj["Cena"] = float(deon[4])
    namestaj["Kategorija"] = deon[5]
    namestaj["Dostupan"] = deon[6]
    return namestaj
</code></pre>

python eclipse pydev