def py3k_bytes(b):
 try:
  return b.tobytes()
 except AttributeError:
  try:
   return ''.join((chr(x) for x in b))
  except TypeError:
   return bytes(b)

def py3k_bytes ( b ) : try : return b . tobytes ( ) except AttributeError : try : return '' . join ( ( chr ( x ) for x in b ) ) except TypeError : return bytes ( b )
emulate the py3k bytes() constructor .