Question: I tried to use the below program

```
import os

HOME= os.getcwd()

STORE_INFO_FILE = os.path.join(HOME,'storeInfo')  

def searchStr(STORE_INFO_FILE, storeId):
    with open (STORE_INFO_FILE, 'r') as storeInfoFile:
        for storeLine in storeInfoFile:
##          print storeLine.split(r'\s+')[0]
            if storeLine.split()[0] == storeId: 
                print storeLine

searchStr(STORE_INFO_FILE, 'Star001')

```

An example line in the file:

> 
> Star001 Sunnyvale 9.00 USD Los\_angeles/America sunnvaleStarb@startb.com
> 
> 
> 

But it gives the below error 

> 
> ./searchStore.py Traceback (most recent call last): File
>  "./searchStore.py", line 21, in 
>  searchStr(STORE\_INFO\_FILE, 'Star001') File "./searchStore.py", line 17, in searchStr
>  if storeLine.split()[0] == storeId: IndexError: list index out of range
> 
> 
> 

I have tried printing using split function on the command line and I was able to print it.

Answer: 
It looks like you have an empty or blank line in your file:

```
>>> 'abc def hij\n'.split()
['abc', 'def', 'hij']
>>> '     \n'.split()    # a blank line containing white space
[]
>>> '\n'.split()         # an empty line
[]

```

The last 2 cases show that an empty list can be returned by `split()`. Trying to index that list raises an exception:

```
>>> '\n'.split()[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

```

You can fix the problem by checking for empty and blank lines. Try this code:

```
def searchStr(store_info_file, store_id):
    with open (store_info_file) as f:
        for line in f:
            if line.strip() and (line.split()[0] == store_id): 
                print line

```

Adding `line.strip()` allows you to ignore empty lines and lines containing only whitespace.
Code has an issue if split method returns an empty list.
You can change code that calls split method and add error handling code.

Following can be done

```
storeLineWords = storeLine.split()
if len(storeLineWords) > 0 and storeLineWords[0] == storeId: 

```