简体   繁体   中英

custom python IDEA debugger type renderer that requires an import

I am trying to add a custom type renderer in the IDEA Python debugger. Specifically, I would like to render an xml Element from the standard xml package as a string, eg <xa=1><y>2</y></x>

The code to do so is ElementTree.tostring(self) where self represents the variable or watch in the debugger.

ElementTree needs to be imported so I have unsuccessful tried:

xml.etree.ElementTree.tostring(self)

and

from xml.etree import ElementTree
ElementTree.tostring(self)

In both cases I got an error Unable to evaluate: name 'xml' is not defined in the debugger watch window. See screenshot:

自定义渲染器错误

The docs don't mention such cases where importing of the rendering function is required.

Has anyone been able to do so?

After further investigation, I managed to get it working with a dynamic import:

__import__('xml').etree.ElementTree.tostring(self)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM