#!/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遍历文件的更多相关文章

  1. python 遍历文件夹 文件

    python 遍历文件夹 文件   import os import os.path rootdir = "d:\data" # 指明被遍历的文件夹 for parent,dirn ...

  2. python遍历文件夹下的文件

    在读文件的时候往往需要遍历文件夹,python的os.path包含了很多文件.文件夹操作的方法.下面列出: os.path.abspath(path) #返回绝对路径 os.path.basename ...

  3. Python遍历文件个文件夹

    在读文件的时候往往需要遍历文件夹,python的os.path包含了很多文件.文件夹操作的方法.下面列出: os.path.abspath(path) #返回绝对路径 os.path.basename ...

  4. 使用python遍历文件夹取出特定的字符串

    # -*- coding: utf-8 -* import re import os # 需要处理的文件夹路径(绝对路径) path = u"/Users/a140/Downloads/te ...

  5. Python 遍历文件夹清理磁盘案例

    import os suffix_name_list = [".pdb", ".ilk"] def find_file(path): # 遍历文件夹 for i ...

  6. python 遍历文件夹下的所有文件

    基础 import os # 遍历文件夹 def walkFile(file): for root, dirs, files in os.walk(file): # root 表示当前正在访问的文件夹 ...

  7. Python遍历文件夹

    许多次需要用python来遍历目录下文件, 这一次就整理了记录在这里. 随实际工作,不定期更新. import os class FileTraversal: def __init__(self, r ...

  8. Python遍历文件夹和读写文件的方法

    需 求 分 析 1.读取指定目录下的所有文件2.读取指定文件,输出文件内容3.创建一个文件并保存到指定目录 实 现 过 程 Python写代码简洁高效,实现以上功能仅用了40行左右的代码~ 昨天用Ja ...

  9. python遍历文件夹中所有文件夹和文件,os.walk

    python中可以用os.walk来遍历某个文件夹中所有文件夹和文件. 例1: import os filePath = 'C:/Users/admin/Desktop/img' for dirpat ...

  10. Python 遍历文件,字符串操作

    写一个简单的脚本,循环遍历单层文件夹,检查源代码中是否有一些特殊的类. import os import codecs dirroot = "......" line_num = ...

随机推荐

  1. SpringBoot配置

    多模块Maven项目 .gitignore文件 .idea *.iml targetout log tmp test 父模块pom文件 <?xml version="1.0" ...

  2. 著名的3像素Bug(div+img,多出几像素)

    <div><img src="...."></div> 给img的css设置display: block;/*用来去除div下边莫名多出来的3p ...

  3. ansible的tests

    Ansible的tests : 路径 /usr/lib/python2.7/site-packages/ansible/plugins/test core.py # failure testing ' ...

  4. RabbitMQ 学习日记

    RabbitMQ三种Exchange模式(fanout,direct,topic)的性能比较 http://www.rabbitmq.com/tutorials/tutorial-one-dotnet ...

  5. MVC中 jquery validate 不用submit方式验证表单或单个元素

    <script src="/Scripts/jquery-1.4.4.js"></script> <script src="/Scripts ...

  6. rabbitmq重启时报错,并导致erlang崩溃和Rabbit的常用命令

    -------------------------------------------------------------------------------------------------- R ...

  7. sql语句表连接删除

    DELETE 表1,表2FROM 表1 LEFT JOIN 表2 ON 表1.id=表2.id WHERE 表1.id=需要删除的ID

  8. fastadmin模态框(弹出框)

    用法: 在html页面新建一个按钮用来触发事件 <a href="javascript:;" class="btn btn-success btn-add &quo ...

  9. python接口测试-认识POST请求

    上午和一个大神交流了一下,给我了一点建议:多做笔记,勤复盘:及时记录自己,最好的提升不是来自于别人,而是来自于自身.我觉得挺有道理的,分享出来.共勉 说正事. 今天把post请求的大概内容看了一下.虽 ...

  10. LeetCode题解 | 215. 数组中的第K个最大元素

    在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 示例 1: 输入: [3,2,1,5,6,4] 和 k = 2 输出: 5 ...