Suppose I have a string of HTML content and would like to extract certain information from it:
pyp "xml.etree.ElementTree.fromstring('<html><head><title>Title</title></head></html>').find('head/title').text"
Even though pyp tried to import xml, there will still be AttributeError: module 'xml' has no attribute 'etree' because of xml.etree.ElementTree’s submodule structure.
I can explicitly use -b parameter for proper importing:
pyp -b "import xml.etree.ElementTree" "xml.etree.ElementTree.fromstring('<html><head><title>Title</title></head></html>').find('head/title').text"
# Title
However, if I add the same line to the PYP_CONFIG_PATH config file, the same AttributeError happens still.
cat $PYP_CONFIG_PATH
# import xml.etree.ElementTree
pyp "xml.etree.ElementTree.fromstring('<html><head><title>Title</title></head></html>').find('head/title').text"
# AttributeError: module 'xml' has no attribute 'etree'
So, the question is:
What is the correct way to have xml.etree.ElementTree imported automatically?
Suppose I have a string of HTML content and would like to extract certain information from it:
pyp "xml.etree.ElementTree.fromstring('<html><head><title>Title</title></head></html>').find('head/title').text"Even though
pyptried toimport xml, there will still beAttributeError: module 'xml' has no attribute 'etree'because ofxml.etree.ElementTree’s submodule structure.I can explicitly use
-bparameter for proper importing:However, if I add the same line to the
PYP_CONFIG_PATHconfig file, the sameAttributeErrorhappens still.So, the question is:
What is the correct way to have
xml.etree.ElementTreeimported automatically?