code: def binary(string, var=None):
      """Makes ``string`` to :class:`str` in Python 2.
      Makes ``string`` to :class:`bytes` in Python 3.
  
      :param string: a string to cast it to :data:`binary_type`
      :type string: :class:`bytes`, :class:`str`, :class:`unicode`
      :param var: an optional variable name to be used for error message
      :type var: :class:`str`
  
      """
      if isinstance(string, text_type):
          return string.encode()
      elif isinstance(string, binary_type):
          return string
      if var:
          raise TypeError(
              "{0} must be a string, not {1!r}".format(var, string)
          )
      raise TypeError("expected a string, not " + repr(string))
  
file_path: wand/wand/compat.py
imports: import collections
  import contextlib
  import io
  import sys
  import types
label_desc: Use image node_id 1 for calling a global function with example usage: binary(string, var) and returns: string, string