parameters: (obj, encoding=None)
docstring: Convert `obj` to binary string (bytes in Python 3, str in Python 2)
docstring_summary: Convert `obj` to binary string (bytes in Python 3, str in Python 2)
docstring_tokens: Convert obj to binary string ( bytes in Python 3 str in Python 2 )
function: def to_binary_string(obj, encoding=None):
      """Convert `obj` to binary string (bytes in Python 3, str in Python 2)"""
      if PY2:
          # Python 2
          if encoding is None:
              return str(obj)
          else:
              return obj.encode(encoding)
      else:
          # Python 3
          return bytes(obj, 'utf-8' if encoding is None else encoding)
function_tokens: def to_binary_string ( obj , encoding = None ) : if PY2 : # Python 2 if encoding is None : return str ( obj ) else : return obj . encode ( encoding ) else : # Python 3 return bytes ( obj , 'utf-8' if encoding is None else encoding )