[英]decorate lxml.etree._Element methods
I tried to decorate/override/patch the 'get' , 'text' , and 'findtext' methods of lxml.etree._Element , but it seems like it's impossible to achieve, as all the attributes are read-only, probably because it's not written in python. 我试图装饰/覆盖/修补“得”,“ 文本”和“FINDTEXT” lxml.etree._Element的方法,但现在看来似乎是不可能实现的,因为所有的属性是只读的,可能是因为它是不是用python编写的。 Is there a way to decorate those methods? 有没有办法装饰这些方法? Thanks for any suggestions.. 感谢您的任何建议。
After reading the comments, I listened to the suggestion to use unicode everywhere, and encode to string just when outputting the data. 阅读注释后,我听了有关在各处使用unicode的建议,并在输出数据时将其编码为字符串。 Thanks for that, however I was curious after all to accomplish the task I wanted anyway, so here's what I've came up with, an lxml._Element class wrapper: 为此,尽管如此,我还是很好奇,无论如何我还是想完成我想要的任务,所以这就是我想出的一个lxml._Element类包装器:
https://github.com/integricho/lxmlproxy https://github.com/integricho/lxmlproxy
Maybe someone else will find it useful for something after all, as I did not find other orthodox solutions. 毕竟,有人可能会发现它对某些事情有用,因为我没有找到其他正统的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.