大學畢業, 想看看大學寫了多少行代碼。
#coding=utf-8import osclass 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的文件方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答