How can count python files in given directory?

Posted on July 14, 2021

def count_py_files_in_repos(dirname):
   # if os.path.exists(os.path.join(dirname, '.git')):
   if os.path.exists(os.path.join(dirname)):
      count = 0
     for root, dirs, files in os.walk(dirname):
        count += len([f for f in files if f.endswith('.py')])
     print(f"{dirname} has {count} python files.")

    for name in os.listdir(dirname):
       path = os.path.join(dirname, name)
       if os.path.isdir(path):


Sign In for comment and like the post.