code: def print_result(result):
      
      try:
          print result
      except UnicodeEncodeError:
          if sys.stdout.encoding:
              print result.encode(sys.stdout.encoding, 'replace')
          else:
              print result.encode('utf8')
      except:
          print "Unexpected error attempting to print result"
docs: Print the result, ascii encode if necessary