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

后端 未结 7 977
太阳男子
太阳男子 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

    Never in a million years. It's unclear what the context for formatting is: locals could include almost any variable. self.__dict__ is not as vague. Perfectly awful to leave future developers scratching their heads over what's local and what's not local.

    It's an intentional mystery. Why saddle your organization with future maintenance headaches like that?

提交回复
热议问题