circularly linked list in python
<p>I am stuck implementing the add function of a circularly linked list in python. I have a head pointer that should be a reference to a node, but every time I add something to the list, head is always None. Here is the code I have so far:</p>

<pre><code>class CircleList():

    __slots__ = ('head', 'size')

    def __init__(self):
        self.head = None
        self.size = 0

    def __str__(self):
        result = "&lt;"
        node = self.head
        count = self.size
        while count != 0:
            result = result + str(node.data)
            if count != 1:
                result = result + ", "
            node = node.next
            count -= 1
        result = result + "&gt;"
        return result

    def add(self, element):
        head = self.head
        print(head)
        size = self.size
        if head == None:
            head = Node(element, None)
            head.next = head
        else:
            cursor = head
            while cursor.next != head:
                cursor = cursor.next
            temp = Node(element, head)
            cursor.next = temp
        size += 1


class Node():
    __slots__ = ('data','next')

    def __init__(self, data, next):
        self.data = data
        self.next = next
</code></pre>

<p>Here is the driver:</p>

<pre><code>stream = open('data.txt', 'r')

circlelist = CircleList()

for name in stream
    circlelist.add(name)

print(circlelist)
</code></pre>
