python2 与Python 3 的区别(持续更新...)

来源:互联网 发布:linux开启ssh 编辑:程序博客网 时间:2024/05/22 12:40

1.csv 读写

#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time    : 2017/4/10 0010 下午 10:17# @Author  : JoJo_feng# @Theme   : # @备注    :import csv#Python 2 读 CSV文件reader=csv.reader(file('a.csv', 'rb'))csvfile = file('9_1_data.csv', 'wb')#Python 3 读 CSV文件with open('a.csv','rb') as csvfile:    reader = csv.reader(csvfile)#Python 2 写 CSV文件csvfile = file('b.csv', 'wb')writer1=csv.writer(csvfile)#Python 3 写 CSV文件with open('b.csv','wb') as f2:    writer2 = csv.writer(f2)


2. Pickle的安装

#Python 2import cPickle#Python 3import pickle

pickle 读取文件

#Python2 import cPickletrain, test, dicts = cPickle.load(open("./dataset/atis.pkl"))#Python3import pickletrain, test, dicts = pickle.load(open("./dataset/atis.pkl",  "rb"),  encoding='iso-8859-1')




3.xrange与range

xrange( )函数时在python 2.x中的一个函数,在Python 3中,range()的实现方式与xrange()函数相同




0 0
原创粉丝点击