zoukankan      html  css  js  c++  java
  • file()拷贝文件 分类: python 20121224 16:44 138人阅读 评论(0) 收藏

    #! /usr/bin/env python
    #coding=utf-8


    #拷贝文件,新创建一个空文件,然后读取另外一个文件poem.txt中的内容,写入新建的文件中


    #创建一个空文件:file_original.txt

    f=file('file_original.txt','a')#追加模式


    #从源文件poem.txt中读取文件

    f2=file('poem.txt')



    n=1


    while True:
        line=f2.readline()#读取poem.txt文件中每行的内容
        
        if len(line)!=0:
            #print line
            f.write(line)
            print 'the %d line content:' % n,line,
            n+=1
        else:
            break

    f.close()
    f2.close()

    输入结果:

    ===============================================

    the 1 line content: 
    the 2 line content: Programming is fun
    the 3 line content: When the work is done
    the 4 line content: if you wanna make your work also fun:
    the 5 line content:     use Python!
    the 6 line content: 
    the 7 line content: LovingJune
    the 8 line content: .........

    ===============================================


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    vb.net FTP上传下载,目录操作
    vb.net导出CSV文件
    服务器内存总量
    定义数组
    监控键盘健代码
    C# FTp 上传,下载
    使用EasyUI中Tree
    微信web开发自定义分享
    mysql将时间戳格式化
    查询表时给字段赋默认值 sql
  • 原文地址:https://www.cnblogs.com/think1988/p/4628261.html
Copyright © 2011-2022 走看看