zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    避免数据脏读
    OGG配置文件中参数化的运用
    GoldenGate基于中间队列文件的初始化
    一次linux中毒,挖矿病毒
    goldengate新版本中查看日志读取点
    dlopen用法参数flag介绍
    gdb调试带参数和调试core
    在现有的git服务器上面创建新的repo
    Play Old Diablo 2 on macOS Catalina
    Odoo中的Environment对象
  • 原文地址:https://www.cnblogs.com/ZhangRuoXu/p/6388918.html
Copyright © 2011-2022 走看看