请问“as if they were Python code”这句话(在回答 Input 和 raw_input 的区别时)该怎么理解?

2017-01-15 15:34:37 +08:00
 Newyorkcity

What's the difference between input() and 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.


from:https://learnpythonthehardway.org/book/ex11.html
谢谢
2396 次点击
所在节点    Python
15 条回复
purebluesong
2017-01-15 15:53:03 +08:00
在 python2 中 input 会把读到的 python 代码跑起来
Izual_Yang
2017-01-15 15:57:31 +08:00
一个是输入纯字符串所以是 raw ,一个是输入表达式所以有安全隐患。另外笨办法学 python 应该有中文翻译版本的吧
lanlanlan
2017-01-15 16:04:52 +08:00
input 会假设用户输入的是合法的 Python 表达式 而 raw_input 会把输入的内容当作原始数据 一般情况下多用 raw_input
chuanqirenwu
2017-01-15 16:25:29 +08:00
As if 只要
congeec
2017-01-15 16:48:58 +08:00
eval()
redhatping
2017-01-15 17:05:21 +08:00
as if 连词 = like (口语习惯)
thekll
2017-01-15 17:06:19 +08:00
'like/as if/as though' is used to say how somebody or something looks/sounds/feels.
'as if' and 'as though' are more formal than 'like'.

After 'as if'(or 'as though'), we sometimes use the past when we are talking about the present.
for example:
'as if they were Python code'
The meaning is not past in this sentence, We use the past('were') because the things you enter for the function input() is not really Python code, it will be converted and run.
arischow
2017-01-15 17:14:20 +08:00
这个有翻译,看不懂可以先去看一眼翻译版本。
shakespark
2017-01-15 18:06:02 +08:00
虚拟语气
zhidian
2017-01-15 18:11:16 +08:00
as if 是“就像”吧。
zingl
2017-01-15 20:23:33 +08:00
中学英语内容吧
N0stalgia
2017-01-15 21:59:15 +08:00
生硬的翻译下,就好像 Python 代码一样。
msg7086
2017-01-16 04:00:24 +08:00
as 表示类比。
if 表示假设。
连在一起:「就好像」。
4ever911
2017-01-16 10:06:02 +08:00
假如,如果
20150517
2017-01-16 17:22:23 +08:00
as if 就好像 我是这么理解的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/334719

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX