V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Newyorkcity
V2EX  ›  Python

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

  •  
  •   Newyorkcity · 2017-01-15 15:34:37 +08:00 · 2395 次点击
    这是一个创建于 2655 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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
    谢谢
    15 条回复    2017-01-16 17:22:23 +08:00
    purebluesong
        1
    purebluesong  
       2017-01-15 15:53:03 +08:00
    在 python2 中 input 会把读到的 python 代码跑起来
    Izual_Yang
        2
    Izual_Yang  
       2017-01-15 15:57:31 +08:00 via Android
    一个是输入纯字符串所以是 raw ,一个是输入表达式所以有安全隐患。另外笨办法学 python 应该有中文翻译版本的吧
    lanlanlan
        3
    lanlanlan  
       2017-01-15 16:04:52 +08:00   ❤️ 1
    input 会假设用户输入的是合法的 Python 表达式 而 raw_input 会把输入的内容当作原始数据 一般情况下多用 raw_input
    chuanqirenwu
        4
    chuanqirenwu  
       2017-01-15 16:25:29 +08:00 via iPhone
    As if 只要
    congeec
        5
    congeec  
       2017-01-15 16:48:58 +08:00 via iPad
    eval()
    redhatping
        6
    redhatping  
       2017-01-15 17:05:21 +08:00
    as if 连词 = like (口语习惯)
    thekll
        7
    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
        8
    arischow  
       2017-01-15 17:14:20 +08:00 via iPhone   ❤️ 1
    这个有翻译,看不懂可以先去看一眼翻译版本。
    shakespark
        9
    shakespark  
       2017-01-15 18:06:02 +08:00
    虚拟语气
    zhidian
        10
    zhidian  
       2017-01-15 18:11:16 +08:00
    as if 是“就像”吧。
    zingl
        11
    zingl  
       2017-01-15 20:23:33 +08:00
    中学英语内容吧
    N0stalgia
        12
    N0stalgia  
       2017-01-15 21:59:15 +08:00
    生硬的翻译下,就好像 Python 代码一样。
    msg7086
        13
    msg7086  
       2017-01-16 04:00:24 +08:00
    as 表示类比。
    if 表示假设。
    连在一起:「就好像」。
    4ever911
        14
    4ever911  
       2017-01-16 10:06:02 +08:00
    假如,如果
    20150517
        15
    20150517  
       2017-01-16 17:22:23 +08:00 via iPhone
    as if 就好像 我是这么理解的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5340 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:09 · PVG 17:09 · LAX 02:09 · JFK 05:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.