Python: is using “..%(var)s..” % locals() a good practice?

后端 未结 7 991
太阳男子
太阳男子 2020-11-27 13:02

I discovered this pattern (or anti-pattern) and I am very happy with it.

I feel it is very agile:

def example():
    age = ...
    name = ...
    pri         


        
7条回答
  •  旧巷少年郎
    2020-11-27 13:39

    I think it is a great pattern because you are leveraging built-in functionality to reduce the code you need to write. I personally find it quite Pythonic.

    I never write code that I don't need to write - less code is better than more code and this practice of using locals() for example allows me to write less code and is also very easy to read and understand.

提交回复
热议问题