没有合适的资源?快使用搜索试试~ 我知道了~
大学毕业, 想看看大学写了多少行代码。 #coding=utf-8 import os class Solution: def __init__(self): self.dirPath = [] def numberOfCode(self,path): for dir in os.listdir(path): childDir = os.path.join(path,dir) if os.path.isdir(childDir): self.numberOfCode(childDir) else: if childDir[-2:] == "py"
资源详情
资源评论
资源推荐
python遍历文件夹找出文件夹后缀为遍历文件夹找出文件夹后缀为py的文件方法的文件方法
大学毕业, 想看看大学写了多少行代码。
#coding=utf-8
import os
class Solution:
def __init__(self):
self.dirPath = []
def numberOfCode(self,path):
for dir in os.listdir(path):
childDir = os.path.join(path,dir)
if os.path.isdir(childDir):
self.numberOfCode(childDir)
else:
if childDir[-2:] == "py":
self.dirPath.append(childDir)
return self.dirPath
def setCode(self):
with open("/home/code.py","ab+") as f:
for file in self.dirPath:
content = open(file,"r").read()
f.write(content)
s = Solution()
s.numberOfCode("/home/py/")
s.setCode()
以上这篇python遍历文件夹找出文件夹后缀为py的文件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也
希望大家多多支持软件开发网。
您可能感兴趣的文章您可能感兴趣的文章:Python引用(import)文件夹下的py文件的方法python获取文件后缀名及批量更新目录下文件后缀名的
方法Python中py文件引用另一个py文件变量的方法
weixin_38547882
- 粉丝: 4
- 资源: 885
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0