大佬教程收集整理的这篇文章主要介绍了如何在使用 os.walk 定义 ROOT_DIR 时从代码源分析中排除子目录和文件,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是试图排除特定文件夹和文件被 pygments 分析。下面的方法给了我一个TypeError: 'str' object does not support item assignment
。我明白 subdir
是一个字符串,但想不出解决它的方法
import os
from pygount import sourceAnalysis
from utils import ROOT_DIR #This is just an absolute path to root dir
class Counter:
def __init__(self):
self.code = 0
self.docs = 0
self.empty = 0
def count(self):
exclude = set(['.mypy_cache','.venv','.vscode','tests','.gitignore','poetry.lock','pyproject.toml'])
for subdir,_,files in os.walk(ROOT_DIR / "TestProject"):
subdir_ = subdir[:] = [s for s in subdir if s not in exclude]
files_ = files[:] = [f for f in subdir if f not in exclude[subdir_]]
for file in (f for f in files_ if f.endswith(".py")):
analysis = sourceAnalysis.from_file(f"{subdir_}/{filE}","pygount",enCoding="utf-8")
self.code += analysis.code_count
self.docs += analysis.documentation_count
self.empty += analysis.empty_count
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的如何在使用 os.walk 定义 ROOT_DIR 时从代码源分析中排除子目录和文件全部内容,希望文章能够帮你解决如何在使用 os.walk 定义 ROOT_DIR 时从代码源分析中排除子目录和文件所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。