using a tail and a buffer to get last K lines in a file
<p>I was given this buffer and told to make a reverse input that get the last K lines in a file. From what I've been trying to do, every time I tried to run the code it says that used is not an attribute of Input. Can someone please tell me why this keeps happening? Thank you in advance.</p>

<pre><code>class Input:
def __init___( self, file ):
    self.file = file # must open( &lt;filename&gt;, "rb" )
    self.length = 0
    self.used = 0
    self.buffer = ""
def read( self ):
    if self.used &lt; self.length:  # if something in buffer 
        c = self.buffer[self.used]
        self.used += 1
        return c
    else:
        self.buffer = self.file.read( 20 ) # or 2048
        self.length = len( self.buffer )
        if self.length == 0:
            return -1
        else:
            c = self.buffer[0]
            self.used = 1

     `
</code></pre>

<p>Try indenting...</p>

<pre><code>class Input:
    def __init___( self, file ):
        self.file = file # must open( &lt;filename&gt;, "rb" )
        self.length = 0
        self.used = 0
        self.buffer = ""
    def read( self ):
        if self.used &lt; self.length:  # if something in buffer 
            c = self.buffer[self.used]
            self.used += 1
            return c
        else:
            self.buffer = self.file.read( 20 ) # or 2048
            self.length = len( self.buffer )
            if self.length == 0:
                return -1
            else:
                c = self.buffer[0]
                self.used = 1
</code></pre>

python file buffer tail