当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | total_num = 0
for base_path,folder_list,file_list in os.walk(target_path):
for file_name in file_list:
file_path = os.path.join(base_path,file_name)
file_ext = file_path.rsplit( '.' ,maxsplit=1)
if len(file_ext) != 2:
# 没有后缀名
continue
if file_ext[1] != 'py' :
# 不是py文件
continue
file_num = 0
with open(file_path, 'rb' ) as f:
for line in f:
# 去空格
line = line.strip()
if not line:
continue
# 去除 # 注释
if line.startswith(b '#' ):
continue
file_num += 1
total_num += file_num
|
以上就是python遍历文件夹下所有文件的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python中pillow知识点学习
Python接单平台有哪些
Python之图形的绘制
学Python要用什么软件
Python打包exe可执行文件
Python输出hello world代码的方法
Python中关于数字的详解
Python利用format方法保留三位小数
Python如何调用c语言函数的使用详解
Python的int是什么
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python遍历文件夹下所有文件