title: Is it a good practice to use decorator to convert all Unicode strings to binary strings?
body: <p>Recently I wrote a little script to connect to servers via telnet (for some reason all the specific programs refused to connect).
  The program was this:</p>
  
  <pre><code>import telnetlib
  tn = telnetlib.Telnet('www.google.com',80)
  tn.write('GET / HTTP/1.0\n')
  tn.write('Host: www.google.com\n')
  tn.write('User-agent: Chrome\n\n')
  out = tn.read_all()
  print(out)
  </code></pre>
  
  <p>It worked perfectly in Python 2.x.
  But then I started using it in Python 3.x and encounter the problem, which was that all the strings as of Python 3.x are Unicode objects. So I started thinking how I can remedy it and came out with a solution using a decorator.</p>
  
  <p>Actually I could have put <code>b</code> before every string (there were only few of them). But I wanted to do it as if it were a huge code snippet (just for training and using good code practice).</p>
  
  <p>The solution with a decorator is the following:</p>
  
  <pre><code>def to_binary(f):
      def wrapper(self, *args):
          s,*args = args
          s = s.encode() #this line performs conversion to binary string
          return f(self, s, *args)
      return wrapper
  
  telnetlib.Telnet.write = to_binary(telnetlib.Telnet.write)
  </code></pre>
  
  <p>My question is:</p>
  
  <p>Is this a good solution to be used in the projects in the future by me? Or I had better prepend every string in <code>tn.write</code> with <code>b</code>, or maybe even use something else?</p>