对于Python中的标准库string template
,是否有一个函数来获取所有标识符的列表?
例如,使用以下xml文件:
<Text>Question ${PrimaryKey}:</Text>
<Text>Cheat: ${orientation}</Text>
该函数将返回PrimaryKey, orientation
答案 0 :(得分:3)
from string import Formatter
s="""<Text>Question ${PrimaryKey}:</Text>
<Text>Cheat: ${orientation}</Text>"""
print([ele[1] for ele in Formatter().parse(s) if ele[1]])
['PrimaryKey', 'orientation']