title: Python: Override method in standard library
body: <p>I had some trouble with the <code>ftplib</code> module in Python 3, after some debugging, I found the mistake: the <code>getline()</code> method of the <code>FTP</code> class returns <code>b'somestring'</code> (but as a string, not bytes) instead of <code>somestring</code>. I can solve this with <code>.decode("utf-8")</code>, replacing the first line in the function</p>
  
  <pre><code>line = self.file.readline(self.maxline + 1)
  </code></pre>
  
  <p>with</p>
  
  <pre><code>line = self.file.readline(self.maxline + 1).decode("utf-8")
  </code></pre>
  
  <p>solves the error. But now, I want not to edit the file <code>ftplib.py</code> manually, instead I want to override it in my code. But while I'm using the <code>FTP_TLS</code> class, which inherits from <code>FTP</code>, I can't figure it out, how to do...</p>
  
  <pre><code>class FTP:
      def getline(self):
          line = self.file.readline(self.maxline + 1).decode("utf-8")
          ...
  </code></pre>
  
  <p>at the beginning in my code does not work, because <code>FTP_TLS</code> doesn't recognize the changes I made to <code>FTP</code>.</p>
  
  <p>Sample:</p>
  
  <pre><code>import ftplib
  import socket
  import ssl
  
  
  class FTP(ftplib.FTP):
      def getline(self):
          line = self.file.readline(self.maxline + 1).decode("utf-8")
          if len(line) &gt; self.maxline:
              raise ftplib.Error("got more than %d bytes" % self.maxline)
          if self.debugging &gt; 1:
              print('*get*', self.sanitize(line))
          if not line:
              raise EOFError
          if line[-2:] == ftplib.CRLF:
              line = line[:-2]
          elif line[-1:] in ftplib.CRLF:
              line = line[:-1]
          return line
  
  
  class FTPS(ftplib.FTP_TLS):
      def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None, timeout=60):
          ftplib.FTP_TLS.__init__(self, host=host, user=user, passwd=passwd, acct=acct, keyfile=keyfile,
                                  certfile=certfile, timeout=timeout)
  
      def connect(self, host='', port=0, timeout=-999, source_address=None):
          if host != '':
              self.host = host
          if port &gt; 0:
              self.port = port
          if timeout != -999:
              self.timeout = timeout
          try:
              self.sock = socket.create_connection((self.host, self.port), self.timeout)
              self.af = self.sock.family
              self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ssl_version=ssl.PROTOCOL_TLSv1_2)
              self.file = self.sock.makefile('rb')
              self.welcome = self.getresp()
          except Exception as e:
              print(e)
          return self.welcome
  
  if __name__ == "__main__":
      ftps = FTPS()
      ftps.connect("host", 990)  # Returns b'welcomemessage'
      ftps.login("user", "pwd")
      ftps.prot_p()
  
      ftps.close()
  </code></pre>