python实现读取大文件并逐行写入另外一个文件

yipeiwu_com6年前Python基础
<pre name="code" class="python">creazy.txt文件有4G,逐行读取其内容并写入monday.txt文件里。 
def creazyRead(): 
  ''''' 
  with open("e:creazy.txt","r") as cr: 
    for line in cr: 
      print line 
  ''' 
  ms = open("e:creazy.txt") 
  for line in ms: 
    with open("e:monday.txt","a") as mon: 
      mon.write(line) 

另一种方法使用readlines实现:

def creazyRead(): 
  ms = open("e:creazy.txt") 
  for line in ms.readlines(): 
    with open("e:monday.txt","a") as mon: 
      mon.write(line) 

以上这篇python实现读取大文件并逐行写入另外一个文件就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python list转dict示例分享

需求:['1:a','2:b','3:c'] 转换为 {'1′: 'a','3′: 'c','2′: ''} 复制代码 代码如下:a = {}b = ['1:a','2:b','3:c'...

对django后台admin下拉框进行过滤的实例

使用django admin 自带后台 admin后台下拉显示的时候需要添加过滤条件, 因为表是自己关联自己,同时还需要过滤掉自己, 需要获取当前对象的id,需要获取obj_id f...

python读取图片并修改格式与大小的方法

本文实例为大家分享了python读取图片并修改文件大小的具体代码,供大家参考,具体内容如下 # Author:NDK # -*- coding:utf-8 -*- from PIL...

Python计算两个日期相差天数的方法示例

本文实例讲述了Python计算两个日期相差天数的方法。分享给大家供大家参考,具体如下: #!/usr/bin/python import time import sys def da...

Python中的lstrip()方法使用简介

 lstrip()方法返回所有字符被去除开头字符串(缺省为空格字符)的一个复本。 语法 以下是lstrip()方法的语法: str.lstrip([chars]) 参...