• python2与python3语法区别之_重定向


    python2与python3两版本的区别是众所周知的,今天主要记录python下版本2 与版本3的区别

    • python2
    In [7]: logfile  = open('/tmp/mylog.log', 'a')
    
    In [8]: print >> logfile, 'writeen by python version 2'
    
    In [9]: logfile.close()
    
    In [10]: cat /tmp/mylog.log
    writeen by python version 2
    
    • python3
    In [1]: help(print)
    Help on built-in function print in module builtins:
    
    print(...)
        print(value, ..., sep=' ', end='
    ', file=sys.stdout, flush=False)
    
        Prints the values to a stream, or to sys.stdout by default.
        Optional keyword arguments:
        file:  a file-like object (stream); defaults to the current sys.stdout.
        sep:   string inserted between values, default a space.
        end:   string appended after the last value, default a newline.
        flush: whether to forcibly flush the stream.
    
    ⇒  ipython
    Python 3.5.1 (default, Jan 23 2017, 08:19:40)
    Type "copyright", "credits" or "license" for more information.
    
    IPython 5.2.2 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: import sys
    
    In [2]: f = open('/tmp/mylog.log', 'w')
    
    In [3]: print('writeen by python version 2', file=f)
    
    In [4]: f.close()
    
    In [5]: cat /tmp/mylog.log
    writeen by python version 2
    writeen by python version 3
    
  • 相关阅读:
    使用DirectX作渲染过程
    记于来北京两个星期
    添加 node mocha 测试模块
    for-of循环
    app-web 开发 追溯debug
    cmd关闭被占用的端口命令及教程详解
    vue使用element-ui的el-input监听不了键盘事件解决
    Nodejs 进阶:Express 常用中间件 body-parser 实现解析
    nodejs设置允许跨域
    nodejs 全局变量和全局对象
  • 原文地址:https://www.cnblogs.com/ZhangRuoXu/p/6388918.html
Copyright © 2020-2023  润新知