python passing function to class
<p>Im writing simple telnetlib based lib, to use by other python scripts. Im also using logging class, and therefore I got one question: Is it possible, and is it good python practice to do things like that:</p>

<pre><code>def printd(args):
    """ debug on stdout """
    sys.stdout.write(time.strftime("%H:%M:%S ") + args.rstrip() + '\n')

def printe(args):
    """ error on stderr """
    sys.stderr.write(time.strftime("%H:%M:%S ") + args.rstrip() + '\n')


class Connections:
    """ Telnet lib connection wrapper """

    def __init__(self, host, port, timeout, logger):
        """ if external logger is passed -  all msgs will be passed to it,
        otherwise will use printd and printe functions """

        self.timeout = timeout
        self.host = host
        self.port = port
        self.connections = {}

        try:
            res = isinstance(logger, logging.Logger)
        except TypeError:
            res = False
        except:
            res = False

        if res == True:
            self.log = logger
            self.log_debug = self.log.debug
            self.log_info = self.log.info
            self.log_error = self.log.error
        else:
            self.log_debug = printd
            self.log_error = printe

    def connect2(self, helloMsg):
        try:
            self.c = telnetlib.Telnet(self.host, self.port)
        except socekt.error:
            self.c = None
            self.log_error("Could not connect to %s:%d" % (self.host, self.port))
        except IOError:
            self.log_error("Could not connect to %s:%d" % (self.host, self.port))
            self.c = None
</code></pre>

<p>In constructor Im passing logger, and if it exist, I want to use its log methods to print messages, if not, I want to use <code>printd</code> and <code>printe</code> functions. </p>
