我正在试验MISP分类法。
!git clone https://github.com/MISP/PyTaxonomies
cd PyTaxonomies
!git submodule init && git submodule update
!python3 setup.py install
from pytaxonomies import Taxonomies
taxonomies = Taxonomies()我想要的是在列表中传递打印结果
for i in taxonomies.values():
print (i)因此,我尝试以下几点:
taxonomies = []
for i in taxonomies.values():
taxonomies.append(i)
taxonomies但是,我回来了
[<pytaxonomies.api.Taxonomy at 0x7f67b1d86250>,
<pytaxonomies.api.Taxonomy at 0x7f67ad048590>,
<pytaxonomies.api.Taxonomy at 0x7f67b14f7b10>,
<pytaxonomies.api.Taxonomy at 0x7f67b14f7550>,
.......
.......
<pytaxonomies.api.Taxonomy at 0x7f67ac805290>,
<pytaxonomies.api.Taxonomy at 0x7f67ac8052d0>,
<pytaxonomies.api.Taxonomy at 0x7f67ac7ecc50>]我希望得到的是:
[CERT-XLM:abusive-content="spam"
CERT-XLM:abusive-content="harmful-speech"
CERT-XLM:abusive-content="violence"
CERT-XLM:malicious-code="virus"
CERT-XLM:malicious-code="worm"
....
....
workflow:state="incomplete"
workflow:state="complete"
workflow:state="draft"
workflow:state="ongoing"
workflow:state="rejected"]有什么办法解决我的问题吗?
发布于 2022-08-22 19:33:05
首先,请注意变量的名称,您重复了taxonomies tice,这可能会破坏变量中的任何数据。对于您的问题,如果列表的值类型是“分类法”类型,这是非常正常的,您只需在之前将它们转换为字符串即可。下面是一个小示例(我还用列表理解来修改it,以获得代码的更短版本):
from pytaxonomies import Taxonomies
# fetching taxonomies
taxonomies = Taxonomies()
# casts the taxonomies output as a string before saving it in a list
taxonomies_out = [str(tax).replace('\n', ' ') for tax in taxonomies.values()]希望这能有所帮助。
https://stackoverflow.com/questions/73449646
复制相似问题