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 = ...
随机推荐
- 【转】解决keepalived正常启动但是虚IP(VIP)没有生成的问题
如题所示,keepalived安装配置好之后能够正常启动,但是虚IP并没有生成.接着检查防火墙(iptables)发现也没有相关的限制.稍微郁闷了一下之后,查看了keepalived日志文件,这次成功 ...
- MySQL查询表中某个字段的重复数据
1. 查询SQL表中某个字段的重复数据 SELECT user_name,COUNT(*) AS count FROM db_user_info GROUP BY user_name HAVING c ...
- Flask开发微电影网站(七)
1.后台管理之电影管理 1.1 定义电影表单 在app的admin目录的forms.py文件中,定义电影表单 # 电影表单 class MovieForm(FlaskForm): title = St ...
- 办公用品管理系统VB——库存数量导出EXCEL,SaveEXCEL
办公用品管理系统VB——库存数量导出EXCEL,SaveEXCEL 总体来说,VB的EXCEL导出效率还是蛮低的,就是一个小型化的办公用品管理软件,不再优化了. 时间紧迫,就没有从头到尾的用C#编写, ...
- 金蝶K3 WISE BOM多级展开_销售成本表
/****** Object: StoredProcedure [dbo].[pro_bobang_SaleCost] Script Date: 07/29/2015 16:13:43 ******/ ...
- Eigen::Matrix与array数据转换
1. 数组转化为Eigen::Matrix ]; cout << "colMajor matrix = \n" << Map<Matrix3i> ...
- ssl证书专题(3):创建CA和申请证书
请看: https://www.cnblogs.com/mingzhang/p/8949541.html
- hdu5707-Combine String(DP)
Problem Description Given three strings a, b and c , your mission is to check whether c is the combi ...
- nginx 错误502 upstream sent too big header while reading response header from upstream
查看nginx的错误日志,得到以下错误信息:upstream sent too big header while reading response header from upstream按字面意思理 ...
- 解决ubuntu下firefox无法在线播放音频和视频的问题
原因 Ubuntu 为了规避专利和版权问题,很多东西没有预装,比如音视频解码器AAC. 那么为什么明明 Ubuntu 上没有AAC解码器, Chrome 却可以正常播放呢,自然的想法是 Chrome ...