在 python 3.x 中删除 raw_input() 的原因是什么? [英] What was the reason for removing raw_input() in python 3.x?
问题描述
为什么现在要和 input()
合并,首先使用它有什么好处?
Why has it now been merged with input()
, and what were the advantages of using it in the first place?
推荐答案
旧的 raw_input
现在称为 input
.它仍然是读取用户输入的默认方式.
The old raw_input
is now called input
. It's still the default way of reading user input.
另一方面,旧的input
用于eval
用户输入的任何内容.然而,eval
是危险的(如果我输入 import os; os.system("something evil")
会发生什么?)所以这个选项被删除了.
The old input
, on the other hand, used to eval
whatever the user entered. eval
, however, is dangerous (what happens if I input import os; os.system("something evil")
?) and so this option was removed.
最初,正如我们从 PEP 3111 中看到的那样,它的目的是删除两者,但他们选择保留 raw_input
的功能,因为它真的很方便.
Originally, as we can see from PEP 3111, it was intended to remove both, but they chose to keep the functionality of raw_input
around, because it was really handy.
旧 input
有害的观点也在 邮件列表,讨论更改时:
The idea that old input
is harmful is also indicated on the mailing lists, when the changes were discussed:
就我个人而言,我认为 input()
不应该存在并且必须去无论.我认为 raw_input()
值得讨论——我不会需要它,但它只不过是一个方便的功能.
Personally, I think
input()
should never have existed and must go no matter what. I thinkraw_input()
is worth discussing -- I wouldn't need it, but it's little more than a convenience function.
如果您真的需要旧的input
,请使用eval(input(...))
.
If you really need old input
, use eval(input(...))
.
这篇关于在 python 3.x 中删除 raw_input() 的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!