python遍历文件
#!/usr/local/bin/python
# -*- coding: UTF-8 -*-
#coding:gbk
import re
import os
rootdir = 'src' def bianli(str,str2):
list = os.listdir(str) #列出文件夹下所有的目录与文件
for i in range(0,len(list)):
w_str=""
w_str1=""
path = os.path.join(str,list[i])
print path
if os.path.isfile(path):
# print path
fopen=open(path,'r')
for line in fopen:
w_str+=line
fopen.close()
list1=re.findall(r"public (.+?)\(",w_str)
for xxx in list1:
aa=xxx.find('(')
bb=xxx.find(' ')
if (aa<0)and(bb<0):
if len(xxx)>12:
w_str1+=xxx+","
str2.write(w_str1)
else:
bianli(path,str2) filee = open('yyypublicll.txt','w')
bianli(rootdir,filee)
filee.close()
#!/usr/local/bin/python
# -*- coding: UTF-8 -*-
#coding:gbk
import re
old_filea=['stage2/main.min.js','stage1/ProtoGJ.min.js','js/default.thm.min.js']
# 生成list
liststring = open('yyypublicll.txt','r')
information=""
for xx in liststring:
information+=xx
listparams = information.split(",")
listparamsqu =list(set(listparams))
listparamsqu.sort(key=listparams.index)
print (listparamsqu)
liststring.close() for x in old_filea:
print "打开文件:"+(x)
number=1
for xxx in listparamsqu:
print (str(number)+xxx)
fopen=open(x,'r')
w_str=""
for line in fopen:
if re.search(xxx,line):
line=re.sub(xxx,'h'+str(number),line)
w_str+=line
else:
# print '1111'
w_str+=line
# print w_str
wopen=open(x,'w')
wopen.write(w_str)
fopen.close()
wopen.close()
number=number+1
#!/usr/local/bin/python
# -*- coding: UTF-8 -*-
#coding:gbk
import re
import os
# 生成list
liststring = open('cc.txt','r')
information=""
number=1
for xx in liststring:
information+=xx
listparams = information.split(",")
xinxi=""
for xxx in listparams:
xinxi=xxx+","+str(number)
print (xinxi)
number=number+1
liststring.close()
raw_input(unicode('按回车键退出...','utf-8').encode('gbk'))
python遍历文件的更多相关文章
- python 遍历文件夹 文件
python 遍历文件夹 文件 import os import os.path rootdir = "d:\data" # 指明被遍历的文件夹 for parent,dirn ...
- python遍历文件夹下的文件
在读文件的时候往往需要遍历文件夹,python的os.path包含了很多文件.文件夹操作的方法.下面列出: os.path.abspath(path) #返回绝对路径 os.path.basename ...
- Python遍历文件个文件夹
在读文件的时候往往需要遍历文件夹,python的os.path包含了很多文件.文件夹操作的方法.下面列出: os.path.abspath(path) #返回绝对路径 os.path.basename ...
- 使用python遍历文件夹取出特定的字符串
# -*- coding: utf-8 -* import re import os # 需要处理的文件夹路径(绝对路径) path = u"/Users/a140/Downloads/te ...
- Python 遍历文件夹清理磁盘案例
import os suffix_name_list = [".pdb", ".ilk"] def find_file(path): # 遍历文件夹 for i ...
- python 遍历文件夹下的所有文件
基础 import os # 遍历文件夹 def walkFile(file): for root, dirs, files in os.walk(file): # root 表示当前正在访问的文件夹 ...
- Python遍历文件夹
许多次需要用python来遍历目录下文件, 这一次就整理了记录在这里. 随实际工作,不定期更新. import os class FileTraversal: def __init__(self, r ...
- Python遍历文件夹和读写文件的方法
需 求 分 析 1.读取指定目录下的所有文件2.读取指定文件,输出文件内容3.创建一个文件并保存到指定目录 实 现 过 程 Python写代码简洁高效,实现以上功能仅用了40行左右的代码~ 昨天用Ja ...
- python遍历文件夹中所有文件夹和文件,os.walk
python中可以用os.walk来遍历某个文件夹中所有文件夹和文件. 例1: import os filePath = 'C:/Users/admin/Desktop/img' for dirpat ...
- Python 遍历文件,字符串操作
写一个简单的脚本,循环遍历单层文件夹,检查源代码中是否有一些特殊的类. import os import codecs dirroot = "......" line_num = ...
随机推荐
- 【译】索引进阶(一):SQL SERVER索引介绍
[译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:http://www.sqlservercentral.com/articles/Stairway+Series/7 ...
- 【原创】大数据基础之Quartz(1)简介、源代码解析
一简介 官网 http://www.quartz-scheduler.org/ What is the Quartz Job Scheduling Library? Quartz is a richl ...
- flex使内部内容自适应宽度
- 【python3 自动化基础之pip】pip常用命令归类
1.升级pippython -m pip install --upgrade pip(包名) 2.安装pymysql pip install pymysql 3.pip按照到指定目录 python - ...
- 怎么给PDF文件交换页面
在使用PDF文件的时候有文件页面的排版错误的时候,这个时候就需要交换页面了,那么怎么给PDF文件交换页面呢,在使用PDF文件的时候需要交换页面的时候要怎么做呢,下面小编就为大家分享一下PDF文件交换页 ...
- OpenCV-Python:形态学操作
常用的形态学操作:腐蚀.膨胀.开运算和闭运算 一.什么叫形态学操作 形态学操作就是改变物体的形状,比如腐蚀就是"变瘦",膨胀就是"变胖" 形态学操作一般作用于二 ...
- Pylon5 SDK搭配OpenCV使用入门
本文假设已经安装了Basler官网提供的Pylon 目前最新的版本是5.0.5,如果上述链接打不开,请直接所有Basler官网下载,需要注意的是在安装Pylon5时要选择Developer模式,这样才 ...
- Java List根据对象的某个属性合并list
package com.test; import java.util.ArrayList; import java.util.List; public class FileTest { public ...
- 527D.Clique Problem
题解: 水题 两种做法: 1.我的 我们假设$xi>xj$ 那么拆开绝对值 $$xi-w[i]>x[j]+w[j]$$ 由于$w[i]>0$,所以$x[i]+w[i]>x[j] ...
- pyqt pyside 设置窗口关闭时删除自身
pyqt pyside 设置窗口关闭时删除自身 self.setAttribute(QtCore.Qt.WA_DeleteOnClose)