def toEncoding(self, s, encoding=None):
if isinstance(s, str):<EOL><INDENT>if encoding:<EOL><INDENT>s = s.encode(encoding)<EOL><DEDENT><DEDENT>elif isinstance(s, str):<EOL><INDENT>if encoding:<EOL><INDENT>s = s.encode(encoding)<EOL><DEDENT>else:<EOL><INDENT>s = str(s)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if encoding:<EOL><INDENT>s  = self.toEncoding(str(s), encoding)<EOL><DEDENT>else:<EOL><INDENT>s = str(s)<EOL><DEDENT><DEDENT>return s<EOL>
Encodes an object to a string in some encoding, or to Unicode.
        .