Get keys from template

后端 未结 7 1000
忘掉有多难
忘掉有多难 2021-01-04 06:56

I would like to get a list of all possible keyword arguments a string template might use in a substitution.

Is there a way to do this other than re?

7条回答
  •  渐次进展
    2021-01-04 07:16

    You could try:

    def get_keys(s):
        tokens = filter(lambda x: x[0] == "$", s.split())
        return map(lambda x: x[1:], tokens)
    

提交回复
热议问题