Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 更改内置类方法的默认参数_Python_Xml_Lxml - Fatal编程技术网

Python 更改内置类方法的默认参数

Python 更改内置类方法的默认参数,python,xml,lxml,Python,Xml,Lxml,我正在我的项目中使用lxml。我有一个输入xml,需要解析它。例如,问题是根元素有xmlns=“some_url” <root xmlns="some_url"> <child>some_text</child> <child>some_text</child> <child> <sub_child>text</sub_child> </child> </root> 因此,我

我正在我的项目中使用
lxml
。我有一个输入xml,需要解析它。例如,问题是根元素有
xmlns=“some_url”

<root xmlns="some_url">
<child>some_text</child>
<child>some_text</child>
<child>
<sub_child>text</sub_child>
</child>
</root>
因此,我的代码中充满了
find
方法,它们具有相同的
namespaces={“nsp”:“some_url”}

如何将此命名空间作为默认名称传递一次?我想我应该继承自
\u SimpleElementPath
类。但是xml元素如何知道使用这个继承的类呢?

如果我错了,有人会纠正我,但我认为lxml没有任何默认名称空间的概念。不幸的是,您总是无法明确地传递名称空间。也许可以为通过名称空间的
findall()
方法编写一个自定义修饰符?

它会是什么样子?我应该将这个装饰器添加到lxml
findall
方法中吗?但在本例中,我更改了lib的代码,这是不可接受的
root.findall("nsp:child/nsp:sub_child", namespaces={"nsp":"some_url"})