"list index out of range" exception (Python3)
<p>I keep getting a list index out of range exception when I check the length of the list a. The error pops up for either the <code>if</code> or <code>elif</code> part of the second <code>if</code> statement, depending on what the user inputs. I know that when the user input is split the list is created correctly because I print it out... So I'm a little lost about why I'm getting that error.</p>

<pre><code>if __name__ == '__main__':
            for line in sys.stdin:
                    s = line.strip()
                    if not s: break
                    if (str(s) is "quit") == True: quit()
                    elif (str(s) is "quit") == False:
                            a = s.split()
                            print(a)
                            if (len(a) == 2) == True: first(a)
                            elif (len(a) == 3) == True: first(a)
                            else: print("Invalid Input. Please Re-enter.")
</code></pre>

<p>The first method is: (The methods it calls in the if statement just print things out at the moment)</p>

<pre><code>def first(self, a = list()):
            word = a[0]

            if word is ls:
                    ls(a[1])           
            elif word is format:
                    form(a[1])        # EDIT: was format
            elif word is reconnect:
                    reconnect(a[1])
            elif word is mkfile:
                    mkfile(a[1])
            elif word is mkdir:
                    mkdir(a[1])
            elif word is append:
                    append(a[1], a[2])                               
            elif word is delfile:
                    delfile(a[1])
            elif word is deldir:
                    deldir(a[1])
            else:
                    print("Invalid Prompt. Please Re-enter.")
</code></pre>

<p>Other methods:</p>

<pre><code>    def reconnect(one = ""):
            print("Reconnect")

    def ls(one = ""):
            print("list")

    def mkfile(one = ""):
            print("make file")

    def mkdir(one = ""):
            print("make drive")

    def append(one = "", two = ""):
            print("append")

    def form(one = ""):
            print("format")

    def delfile(one = ""):
            print("delete file")

    def deldir(one = ""):
            print("delete directory")

    def quit():
            print("quit")
            sys.exit(0)
</code></pre>

<h2>Real issue:</h2>

<p>To solve your error you have to <strong>remove</strong> the <code>self</code> parameter of the <code>first</code> function  </p>

<pre><code>def first(a=list())
</code></pre>

<p>Basically the <strong>self</strong> is only used for object orientation creating methods. 
Function like yours can't use self otherwise you will passing the first parameter to self not to a which you want to. </p>

<p>My second issue I can point out is that, You are trying to compare using <code>is</code> between a <strong>string</strong> and a <strong>function</strong>. </p>

<pre><code> def first(a = list()):
        word = a[0]

        if word is "ls":
                ls(a[1])           
        elif word is "format":
                format(a[1])
        elif word is "reconnect":
                reconnect(a[1])
        elif word is "mkfile":
                mkfile(a[1])
        elif word is "mkdir":
                mkdir(a[1])
        elif word is "append":
                append(a[1], a[2])                               
        elif word is "delfile":
                delfile(a[1])
        elif word is "deldir":
                deldir(a[1])
        else:
                print("Invalid Prompt. Please Re-enter.")
</code></pre>

<h2>Extra</h2>

<p>The <code>is</code> function on built in operations in Python. <code>is</code> compare the equity of the objects. </p>

<p>But this expression: </p>

<pre><code>if (str(s) is "quit") == True:
</code></pre>

<p>Can be simpler like:</p>

<pre><code>if str(s) == "quit":
</code></pre>

<p>Or: </p>

<pre><code>if str(s) is "quit":
</code></pre>

<p>The <code>== True</code> is meaningless either <code>== False</code> you can use <code>not</code> more pythonicly. </p>

python list