list our of range in python
<p>I have a code in python to index a text file that contain arabic words. I tested the code on an english text and it works well ,but it gives me an error when i tested an arabic one.
Note: the text file is saved in unicode encoding not in ANSI encoding.</p>

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

<pre><code>from whoosh import fields, index
import os.path
import csv
import codecs
from whoosh.qparser import QueryParser

# This list associates a name with each position in a row
columns = ["juza","chapter","verse","voc"]

schema = fields.Schema(juza=fields.NUMERIC,
                       chapter=fields.NUMERIC,
                       verse=fields.NUMERIC,
                       voc=fields.TEXT)

# Create the Whoosh index
indexname = "indexdir"
if not os.path.exists(indexname):
  os.mkdir(indexname)
ix = index.create_in(indexname, schema)

# Open a writer for the index
with ix.writer() as writer:
  with open("h.txt", 'r') as txtfile:
    lines=txtfile.readlines()

    # Read each row in the file
    for i in lines:

      # Create a dictionary to hold the document values for this row
      doc = {}
      thisline=i.split()
      u=0

      # Read the values for the row enumerated like
      # (0, "juza"), (1, "chapter"), etc.
      for w in thisline: 
        # Get the field name from the "columns" list
          fieldname = columns[u]
          u+=1
          #if isinstance(w, basestring):
          #     w = unicode(w)
          doc[fieldname] = w
      # Pass the dictionary to the add_document method
      writer.add_document(**doc)
with ix.searcher() as searcher:
    query = QueryParser("voc", ix.schema).parse(u"بسم")
    results = searcher.search(query)
    print(len(results))
    print(results[1]) 
</code></pre>

<p>Then the error is :</p>

<pre><code>Traceback (most recent call last):
  File "C:\Python27\yarab.py", line 38, in &lt;module&gt;
    fieldname = columns[u]
IndexError: list index out of range
</code></pre>

<p>this is a sample of the file:</p>

<pre><code>1   1   1   كتاب
1   1   2   قرأ
1   1   3   لعب
1   1   4   كتاب
</code></pre>
