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设计】。

相关文章

使用OpenCV-python3实现滑动条更新图像的Canny边缘检测功能

使用OpenCV-python3实现滑动条更新图像的Canny边缘检测功能

import cv2 from matplotlib import pyplot as plt import numpy as np img= cv2.imread('39.jpg...

pytorch下使用LSTM神经网络写诗实例

在pytorch下,以数万首唐诗为素材,训练双层LSTM神经网络,使其能够以唐诗的方式写诗。 代码结构分为四部分,分别为 1.model.py,定义了双层LSTM模型 2.data.py...

解决python3在anaconda下安装caffe失败的问题

Python 跟 Python3 完全就是两种语言 1、 import caffe FAILED  环境为 Ubuntu 16 cuda 8.0 NVIDIA 361.77...

python 实现快速生成连续、随机字母列表

0.摘要 本文介绍了生成连续和随机字母表的方法,用于快速生成大量字母数据。 主要使用chr()函数,将数字通过ASCII表转换为相应字母。 1.chr() 函数 chr() 用一个范围在...

Python去除字符串前后空格的几种方法

其实如果要去除字符串前后的空格很简单,那就是用strip(),简单方便 >>> ' A BC '.strip() 'A BC' 如果不允许用strip()的方法,...