我在阅读David Goodger的像Pythonista一样编写代码:Python惯用法时,偶然发现了以下警告。
我正试图理解使用Excerpt from the article ...
print('Hello %(name)s, you have %(messages)i messages' % locals())
This is very powerful. With this, you can do all the string formatting you want without having to worry about matching the interpolation values to the template.
But power can be dangerous. "With great power comes great responsibility." If you use the
locals()
from with an externally-supplied template string, you expose your entire local namespace to the caller. This is just something to keep in mind.
locals()
可能存在潜在风险的具体场景。欢迎提供locals()
存在的情况下可能被利用的任何示例。谢谢!