写一个简单的脚本,循环遍历单层文件夹,检查源代码中是否有一些特殊的类。

  1. import os
  2. import codecs
  3. dirroot = "......"
  4. line_num = 0
  5. def ContainsSpecialWords(line):
  6. for w in ["Double","Integer","Float","Long","Date"]:
  7. if w in line:
  8. if "//" not in line:
  9. return True
  10. return False
  11. for parent,dirnames,filenames in os.walk(dirroot):
  12. print("enter: " + dirroot)
  13. for filename in filenames:
  14. file = dirroot + filename
  15. print("read " + file)
  16. fin = codecs.open(file,'r','utf-8')
  17. lineNumber = 0
  18. for lines in fin:
  19. lineNumber = lineNumber + 1
  20. if ContainsSpecialWords(lines):
  21. print("at row number: " + str(lineNumber) + " " + lines)
  22. fin.close()

Python 遍历文件,字符串操作的更多相关文章

  1. python入门7 字符串操作

    字符串操作 #coding:utf-8 #/usr/bin/python """ 2018-11-03 dinghanhua 字符串操作 ""&quo ...

  2. 一句python,一句R︱python中的字符串操作、中文乱码、NaN情况

    一句python,一句R︱python中的字符串操作.中文乱码.NaN情况 先学了R,最近刚刚上手Python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句pytho ...

  3. 【Python自动化Excel】Python与pandas字符串操作

    Python之所以能够成为流行的数据分析语言,有一部分原因在于其简洁易用的字符串处理能力. Python的字符串对象封装了很多开箱即用的内置方法,处理单个字符串时十分方便:对于Excel.csv等表格 ...

  4. python 遍历文件夹 文件

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

  5. Python中的字符串操作总结(Python3.6.1版本)

    Python中的字符串操作(Python3.6.1版本) (1)切片操作: str1="hello world!" str1[1:3] <=> 'el'(左闭右开:即是 ...

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

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

  7. python对文件的操作

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件 ...

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

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

  9. Python遍历文件个文件夹

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

  10. python关于文件的操作

    总是记不住API.昨晚写的时候用到了这些,但是没记住,于是就索性整理一下吧: python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Pyth ...

随机推荐

  1. curl模拟自动登陆&采集网页数据

    <!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content=&quo ...

  2. WebApp的前端所遇问题

    2015年10月1日至10月25日,两个本科生和一位研究生以及一位老师组成四人团队,开发某教育前端项目 所遇问题总结以及分享: 一.主要应用软件:sublime_text HBuilder 初学者可以 ...

  3. 中文的加密传输(python版)

    信息传输过程中,可能会被各种监听. 这里介绍一种简单的加密算法(可逆). 正向加密: 字符串 -> 字节(char->int转换) -> 异或每个字节某个KEY  ->字节(i ...

  4. python 的dict的update 方法的一点诡秘的行为

    如下: >>> 'a%s'%a 'a{1: 0, 2: 0}' >>> for k,v in a.items(): a.update(k=v) >>&g ...

  5. python 端口扫描仪

    思路:使用socket进行连接测试,即客户端连接服务器. 核心代码如下: from socket import * def try_port(ip,port,protocol = SOCK_STREA ...

  6. bootstrap按钮组

    种类 -a,   input ,   button 块级 btn-block 按钮组 btn-group btn-group-justified btn-group-vertical </div ...

  7. ubuntu14.04 us sources.list

    deb http://us.archive.ubuntu.com/ubuntu/ trusty main restricted deb-src http://us.archive.ubuntu.com ...

  8. struts2 提供的校验器列表

  9. struts2 如何实现mvc 的?

  10. Django~Databases

    更换数据库 migrate 下哈 admin 要重新建立 修改\mysite\settings.py DATABASES = {    'default': {        'ENGINE': 'd ...