title: Variable equivalent of b'some string' in python
body: <p>what is the best equivalent way to do <code>b'some string'</code> but with a string variable? I've tried <code>b(somevar)</code> but that doesn't work. I saw some to byte array functions but I'm not sure if that's over complicating it as for literal strings a simple <code>b</code> placed in front of the string is enough.</p>
  
  <p>The end goal, before I'm down voted to no end lol, is to use strings for telnet connections. For simple writes I can do <code>b'ehlo a.com'</code> as an example. But if I have say <code>'ehlo a.com'</code> stored as a string var, how can I use that?</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>writestring = 'RCPT TO: postmaster@'+domains[domain]
  bytesdata = writestring.encode('ascii')
  tn.write(writestring)
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__
      return self.func(*args)
    File "C:\Users\kylec\Desktop\DataMotion\Python\MailChecker.py", line 108, in checkMail
      tn.write(writestring)
    File "C:\Python34\lib\telnetlib.py", line 289, in write
      if IAC in buffer:
  TypeError: 'in &lt;string&gt;' requires string as left operand, not bytes
  </code></pre>