Why should exec() and eval() be avoided?

后端 未结 11 1977
Happy的楠姐
Happy的楠姐 2020-11-22 00:16

I\'ve seen this multiple times in multiple places, but never have found a satisfying explanation as to why this should be the case.

So, hopefully, one will be prese

11条回答
  •  爱一瞬间的悲伤
    2020-11-22 00:48

    Try this in the interactive interpreter and see what happens:

    >>> import sys
    >>> eval('{"name" : %s}' % ("sys.exit(1)"))
    

    Of course, this is a corner case, but it can be tricky to prevent things like this.

提交回复
热议问题