How can I extract keywords from a Python format string?

前端 未结 4 1692
梦谈多话
梦谈多话 2020-11-29 06:13

I want to provide automatic string formatting in an API such that:

my_api(\"path/to/{self.category}/{self.name}\", ...)

can be replaced wit

4条回答
  •  天涯浪人
    2020-11-29 06:24

    You can do "path/to/{self.category}/{self.name}".format(self=self). You could thus work with those kwargs in __getattr__.

提交回复
热议问题