欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)文件內(nèi)容批量追加的方法示例

 更新時(shí)間:2017年08月29日 12:01:50   作者:我才是二亮  
這篇文章主要介紹了Python實(shí)現(xiàn)文件內(nèi)容批量追加的方法,結(jié)合實(shí)例形式分析了Python文件的讀寫(xiě)相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python實(shí)現(xiàn)文件內(nèi)容批量追加的方法。分享給大家供大家參考,具體如下:

#coding:utf-8
import os
#-------代碼段一
#獲取當(dāng)前文件夾
filePath = os.getcwd()
#獲取當(dāng)前文件列表
fileNameList = os.listdir(filePath)
fileDirList = []
#獲取文件路徑列表
for fileName in fileNameList:
  fileDirList.append(os.path.join(filePath, fileName))
#--------代碼段二
f = open('code.txt', 'w')
f.write("開(kāi)始寫(xiě)文件\n")
f.close()
for code in fileDirList:
  f = open('code.txt', 'a')
  split = os.path.splitext(code)
  if(split[1] == '.h' or split[1] == '.cpp'):
    fz = open(code, 'r')
    string = "源代碼文件" + code +"代碼:\n"
    f.write(string)
    content = fz.read()
    print "文件 %s 讀寫(xiě)成功" % code
    f.write(content)
    fz.close()
  f.close()
print "讀寫(xiě)成功"

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python URL操作技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門(mén)與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論