#!/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. 求逆序对常用的两种算法 ----归并排 & 树状数组

    网上看了一些归并排求逆序对的文章,又看了一些树状数组的,觉得自己也写一篇试试看吧,然后本文大体也就讲个思路(没有例题),但是还是会有个程序框架的 好了下面是正文 归并排求逆序对 树状数组求逆序对 一. ...

  2. Codeforces 877E - Danil and a Part-time Job 线段树+dfs序

    给一个有根树,1e5个节点,每个节点有权值0/.1,1e5操作:1.将一个点的子树上所有点权值取反2.查询一个点的子树的权值和   题解: 先深搜整颗树,用dfs序建立每个点对应的区间,等于把树拍扁成 ...

  3. IEnumerable<T>和IQueryable<T>区别

    LINQ查询方法一共提供了两种扩展方法,在System.Linq命名空间下,有两个静态类:Enumerable类,它针对继承了IEnumerable<T>接口的集合进行扩展:Queryab ...

  4. python学习第22天

    封装 properpty classmathod staticmathod

  5. Mysql -- 数据类型(2)

    掌握char类型和varchar类型 掌握枚举类型和集合类型 字符类型 #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和v ...

  6. VUE项目的目录关系

    1.页面中只有一个index.html. 2.一个js文件.在路由中. 3.主要的app.vue. 4.最后就是可以放多个vue文件的~~(一个页面对应一个vue文件,一个vue组件对应一个js中的i ...

  7. js-检测字符串出现次数最多,并返回

    function validateStr(val){ let obj = {}; let maxNum = -1; let maxStr; for(let i=0;i<val.length;i+ ...

  8. Python虚拟环境的安装与使用

    通过virtualenv创建 首先安装virtualenv:pip3 install virtualenv 安装完成之后cd到合适的目录下键入命令: virtualenv 虚拟环境名称 (创建纯净的虚 ...

  9. windows10 php7安装mongodb 扩展及其他扩展的思路

    1. 打开phpinfo 查看 nts(非线程) 还是 ts (线程),然后查看操作位数 注: 86 等于 32 位 ,和你的windows系统64 or 32位无关.比如我的: 2. 下载对应的版本 ...

  10. Scapy

    1.UDP scanning with Scapy Scapy is a tool that can be used  to craft and inject custom packets into  ...