Q:

Comparing a returned "value" with a string in python

I have a python script which makes a Linked List of the input and then compares the characters to make sure that all opened brackets have close brackets in the right order.
Eg. (9-{5*2(1+1)}) == True
    (9-{5*2{1+1))) == False
My problem comes to when I'm comparing the return value of a function with a string. The if function just halts at the line 152. When I interrupt the script I get this error:
Traceback (most recent call last):
  File "lab2.py", line 195, in <module>
    bracketCheck(list)
  File "lab2.py", line 152, in bracketCheck
    if list.getNodeAtPosition(i) == '(' or list.getNodeAtPosition(i) == '{' or list.getNodeAtPosition(i) == '[':
      File "lab2.py", line 114, in getNodeAtPosition
    currentNode = currentNode.getNext()
KeyboardInterrupt

The Code of my script where the Linked List is heavily inspired by atraub from DreamInCode is below. Also, the inputs have to be entered one at a time until you type in "done":
import sys

stack = []
openbrackets = ['(','{','[']
closebrackets = [')','}',']']

class LinkedList:
    class Node:
        def __init__ (self, cargo=None):
            self.cargo = cargo
            self.next = None

        def __str__ (self):
            return str(self.cargo)

        def __len__ (self):
            return self.length

        def isEmpty (self):
            if length == 0:
                return True
            else:
                return False 

        def getElement(self):
            print self.__str__()

        def getNext (self):
            return self.next 

        def setElement(self, cargo):
            self.cargo = cargo

        def setNext(self, cargo):
            self.next = cargo

        def hasNext(self):
            return self.next != None

    def __init__(self):
        self.first = LinkedList.Node()
        self.length = 0     

    def __len__ (self):
        return self.length

    def __add__(self, other):
        retList = LinkedList()
        for item in self:
            retList.append(item)
        for item in other:
            retList.append(item)

        return retList

    def getFirst(self):
        return self.first.getNext()

    def currentPoint(self):
        current = self.first.getNext()

    def setFirst(self, cargo):
        toAdd = LinkedList.Node(cargo)
        toAdd.setNext(self.first.getNext())
        self.first.setNext(toAdd)
        self.length += 1

    def removeFirst(self):
        if self.length > 0:
            value = self.first.getNext().getElement()
            self.first.setNext(self.first.getNext().getNext())
            self.length -= 1
            return value
        else:
            print "Error: List is empty"

    def addLast(self, cargo):
        current = self.first

        while current.hasNext():
            current = current.getNext()

        current.setNext(LinkedList.Node(cargo))
        self.length += 1

    def removeLast(self,index=None):
        if index ==None: 
            index = self.length-1

        previous = self.getNodeAtPosition(self.checkIndex(index)-1)
            toRemove = previous.getNext()
            afterNext = None
            if toRemove.hasNext():
                    afterNext = toRemove.getNext()
            previous.setNext(afterNext)
            self.length-=1
            return toRemove.getElement()

    def getLast(self):
        current = self.first

        while current.hasNext():
            current = current.getNext()

        return current

    def moveNext(self):
        current = self.first

    def getNodeAtPosition(self, index):
        currentNode = self.first
        for i in range(index+1):
            currentNode = currentNode.getNext()
        return currentNode

    def __str__ (self):
        if self.length == 0:
            return '[]'

        retString = "["
        currentElement = self.first.getNext()

        for i in range(self.length):
            retString += str(currentElement) + ", "
            currentElement = currentElement.getNext()

        return retString[:-2] + ']'

    def checkIndex(self, index):
        if type(index) != int:
            raise TypeError("Index must be an integer or a slice not a")

        if index < 0:
            index += self.length

        if index >= self.length or index < 0:
            raise IndexError("Index out of bounds")

        return index

def bracketCheck(list):
    checkList = LinkedList()
    opencount=0
    closecount=0

    while(list.first.hasNext):
        isEqual = True
        i=0
        i=i+1
        if list.getNodeAtPosition(i) == '(' or list.getNodeAtPosition(i) == '{' or list.getNodeAtPosition(i) == '[':
            checkList.addLast(list.first.getNodeAtPosition(i))
            opencount = opencount + 1

        if list.getNodeAtPosition(i) == ')':
            closecount = closecount + 1

            if list.first.getLast() == openbrackets[0]:
                checkList.removeLast()
            else:
                isEqual = False

        if list.getNodeAtPosition(i) == '}':
            closecount = closecount + 1

            if list.first.getLast() == openbrackets[1]:
                checkList.removeLast()
            else:
                isEqual = False

        if list.getNodeAtPosition(i) == ']':
            closecount = closecount + 1

            if list.first.getLast() == openbrackets[2]:
                checkList.removeLast()
            else:
                isEqual = False
    '''print checkList'''
    print opencount
    print closecount
    if isEqual == False:
        print "an extra is missing."
    else:
        print "win!"

print "Enter list:"
list = LinkedList()
while input != "done":
    input = raw_input()
    if input == "done":
        break
    list.addLast(input)

print list
bracketCheck(list)

A:

There are so many logical errors in your code that I lost count.. 
The following modified code works well (based on my basic testing), please do a diff and try to see the errors in your original code: 
def bracketCheck(myList):
    checkmyList = LinkedList()
    opencount=0
    closecount=0
    i=0
    isEqual = True
    while(i < myList.length):
        i=i+1
        if myList.getNodeAtPosition(i-1).cargo == '(' or myList.getNodeAtPosition(i-1).cargo == '{' or myList.getNodeAtPosition(i-1).cargo == '[':
            checkmyList.addLast(myList.getNodeAtPosition(i-1))
            opencount = opencount + 1
        if myList.getNodeAtPosition(i-1).cargo == ')':
            closecount = closecount + 1
            if checkmyList.getLast().__str__() == openbrackets[0]:
                checkmyList.removeLast()
            else:
                isEqual = False

        if myList.getNodeAtPosition(i-1).cargo == '}':
            closecount = closecount + 1
            if checkmyList.getLast().__str__() == openbrackets[1]:
                checkmyList.removeLast()
            else:
                isEqual = False

        if myList.getNodeAtPosition(i-1).cargo == ']':
            closecount = closecount + 1
            if checkmyList.getLast().__str__() == openbrackets[2]:
                checkmyList.removeLast()
            else:
                isEqual = False
    '''print checkmyList'''
    print opencount
    print closecount
    if isEqual == False:
        print "an extra is missing."
    else:
        print "win!"

print "Enter myList:"
myList = LinkedList()
while input != "done":
    input = raw_input()
    if input == "done":
        break
    myList.addLast(input)

print myList
bracketCheck(myList)

Please bare in mind the code above isn't pythonic or even "decent". It is barely here for you to see the logical flaws in your original code. 
If you want a pythonic solution, please refer to @yak's answer.

