From 03ec0495409826669338ded2961fd8e147ab3cf1 Mon Sep 17 00:00:00 2001 From: Humza Date: Wed, 20 Apr 2022 02:41:37 -0500 Subject: [PATCH] Print regular UTF-8 string instead of bytes-string Printing a bytes string looks unreadable in the terminal e.g. b'\n \n' What we want is more like: Specify encoding to do this Works for both xml and lxml https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring https://lxml.de/3.6/api/lxml.etree-module.html#tostring --- astpath/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astpath/search.py b/astpath/search.py index 81b77e3..2dbb6cd 100644 --- a/astpath/search.py +++ b/astpath/search.py @@ -179,7 +179,7 @@ def search( if print_xml: tostring = _tostring_factory() for element in matching_elements: - print(tostring(xml_ast, pretty_print=True)) + print(tostring(xml_ast, pretty_print=True, encoding='unicode')) matching_lines = linenos_from_xml(matching_elements, query=query, node_mappings=node_mappings) global_matches.extend(zip(repeat(filename), matching_lines))