我正在阅读这个 Python 2.7 教程,他们正在阅读 raw_input()
,其中提到:
The input() function will try to convert things you enter as if they
were Python code, but it has security problems so you should avoid it.
我试着用谷歌搜索一些解释,但我还是有点不清楚; input()
vs raw_input()
所谓的固有安全问题的简单解释是什么?
Python 2.x 中的 input()
函数会在返回之前评估事物。
作为示例,您可以看一下这个 -
>>> input("Enter Something : ")
Enter Something : exit()
这会导致程序退出(因为它会评估 exit())。
另一个例子-
>>> input("Enter something else :")
Enter something else :__import__("os").listdir('.')
['.gtkrc-1.2-gnome2', ...]
这将列出当前目录的内容,您还可以使用 os.chdir()
、 os.remove()
、 os 等函数.removedirs()
, os.rmdir()