#!/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. ASP.NET Web API 之一 入门篇

    一.基于RESTful标准的Web Api 原文讲解:https://www.cnblogs.com/lori/p/3555737.html 微软的web api是在vs2012上的mvc4项目绑定发 ...

  2. ROS-十步完成ROS-indigo安装

    Ubuntu 版本是14.04.5.(这个版本的ubuntu的内核是V4.4的内核,长期维护到2019年,是14代比较稳定的,反正用这个安装就没有什么依赖的头疼的问题,安装ROS很方便,可以去清华的网 ...

  3. 【原创】大叔经验分享(4)Yarn ResourceManager页面如何实现主被自动切换

    hdfs.yarn.hbase这些组件的master支持多个,实现自动主备切换,其中hdfs.hbase无论访问主master或者备master都可以正常访问页面,但是yarn比较特别,只有主mast ...

  4. 【原创】大叔问题定位分享(23)Ambari安装向导点击下一步卡住

    ambari安装第一步是输入集群name,点击next时页面卡住不动,如下图: 注意到其中一个接口请求结果异常,http://ambari.server:8080/api/v1/version_def ...

  5. Scrapy-redis 分布式

    分布式:架构方式 多台真实机器+爬虫(如requests,scrapy等)+任务共享中心 多台虚拟机器(或者部分虚拟部分真实)+爬虫(如requests,scrapy等)+任务共享中心 多台容器级虚拟 ...

  6. matplotlib学习笔记

    1.简介 matplotlib是python的一个2D绘图库,它可以在不同平台上地使用多种通用的绘图格式(hardcopy formats)和交互环境绘制出出版物质量级别的图片.matplotlib可 ...

  7. 使用font awesome制作网站常用社交工具联系方式图标

    在公司项目或者个人建站时经常会有这么一个需求,就是在网站的底部以图标的形式加入自己的某些常用社交联系方式,比如QQ.微信.微博.Twitter等等,如果采用传统切图的方式去制作这些图标会有两个缺点: ...

  8. 完整备份和差异备份数据库的SQL脚本

    工作中需要创建SQL Job对数据库进行定期备份,现把脚本记录如下. 1. 完整备份: -- FULL declare @filename varchar(1024), @file_dev varch ...

  9. HTML5全屏浏览器兼容方案

    最近一个项目有页面全屏的的需求,搜索了下有HTML5的全屏API可用,不过各浏览器的支持不一样. 标准 webkit  Firefox  IE Element.requestFullscreen() ...

  10. CAP分布式事务 学习及简单demo

    完全参考 github的指导 demo地址, Pub使用 efcore , Sub 使用 dapper, mysql数据库 https://files.cnblogs.com/files/xtxtx/ ...