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='\n', 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
python2与python3语法区别之_重定向的更多相关文章
- python2 与 python3 语法区别
python2 与 python3 语法区别 概述# 原稿地址:使用 2to3 将代码移植到 Python 3 几乎所有的Python 2程序都需要一些修改才能正常地运行在Python 3的环境下.为 ...
- python2 与 python3 语法区别--转
原文地址:http://old.sebug.net/paper/books/dive-into-python3/porting-code-to-python-3-with-2to3.html 使用2t ...
- Python2和Python3语法区别
1.使用for循环进行换行 python 2.x, print 不换行>>> print x, python 3.x print 不换行>>> print(x, e ...
- python2 与 python3的区别
python2 与 python3的区别 几乎所有的python2程序都需要一些修改才能正常的运行在python3的环境下.为了简化这个转换过程,Python3自带了一个2to3的实用脚本.这个脚本会 ...
- python2 与 python3的区别总结
python2 与 python3的区别总结 几乎所有的Python 2程序都需要一些修改才能正常地运行在Python 3的环境下.为了简化这个转换过程,Python 3自带了一个叫做2to3的 ...
- 详解python2 和 python3的区别
看到这个题目大家可能猜到了我接下来要讲些什么,呵呵,对了,那就是列出这两个不同版本间的却别!搜索一下大家就会知道,python有两个主要的版本,python2 和 python3 ,但是python又 ...
- 详解python2 和 python3的区别-乾颐堂
看到这个题目大家可能猜到了我接下来要讲些什么,呵呵,对了,那就是列出这两个不同版本间的却别!搜索一下大家就会知道,python有两个主要的版本,python2 和 python3 ,但是python又 ...
- python2和python3的区别
python2和python3的区别 参考链接:http://www.runoob.com/python/python-2x-3x.html 1.源码上的区别 python2 python3 源码不规 ...
- while 运算符 初始编码 python2和python3的区别
1.while 循环 2.运算符 3.初始编码 4.python2 和python3的区别 1.while循环: 关键词:while[循环] break[跳出循环] c ...
随机推荐
- 较快的maven的settings.xml文件
<?xml version="1.0" encoding="UTF-8"?> <settings> <!-- <localR ...
- HDU 2157 How many ways??(简单线性DP | | 矩阵快速幂)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2157 这道题目很多人的题解都是矩阵快速幂写的,矩阵快速幂倒是麻烦了许多了.先给DP的方法 dp[i][ ...
- Servlet------>jsp自定义标签3(不显示余下jsp内容)
2.自定义标签控制,jsp页面余下标签是否继续执行 EndTag.java package tag; import javax.servlet.jsp.JspException; import jav ...
- vue项目中批量打印二维码
前提:项目中要打印的二维码为后台返回,批量选择后,点击打印,先打开二维码预览界面,再执行打印. 以下代码中 codePicList为选中的二维码数组.重点css:page-break-after:al ...
- 前端开发 - JavaScript - 下
12.数组 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- LeetCode_Insertion Sort List
题目:Sort a linked list using insertion sort,即仿照插入排序(直接插入排序)对一个链表排序. 插入排序的思想:总共进行n-1趟排序,在排列第i个元素时,前面的i ...
- Spring的IOC底层实现
IOC的底层实现 续图:
- geo实现方案
1.数据库内在支持GIS(地理信息系统) MySQL: 目前只有MyISAM引擎是支持GIS的,Innodb在5.7版本中才支持空间索引.MyISAM这个引擎不支持事务.外键,而且是表锁.适合读为主, ...
- PAT 1136 A Delayed Palindrome[简单]
1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 ...
- macOS Sierra上Opencv的安装与使用
安装cmake brew install cmake 安装OpenCV brew install opencv //opencv升级 # brew upgrade opencv 配置OpenCV环境: ...