如何在python中使用filter list进行字符串过滤

2024-10-03 23:30:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从iniFile中筛选一个字符串,并将其转换为名为iniConf的dict:

iniFile ='''

conf = test.ini

\# conf = test2.ini
conf_type = single

\#conf_type = multi
'''

infilter = ['conf', 'conf_type'] # to use
exfilter = ['#', 'multi'] # to skip

过滤后,我想得到

iniConf = {'conf':'test.ini', 'conf_type':'single'}

Tags: to字符串testuseconftypemultiini