You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
701 B
31 lines
701 B
'''
|
|
Author: SJ2050
|
|
Date: 2021-10-16 21:14:15
|
|
LastEditTime: 2021-10-16 23:24:52
|
|
Version: v0.0.1
|
|
Description: Solution for homework10.
|
|
Copyright © 2021 SJ2050
|
|
'''
|
|
import os
|
|
|
|
if __name__ == '__main__':
|
|
res = {}
|
|
dir_path = './test/'
|
|
files= os.listdir(dir_path)
|
|
|
|
for file in files:
|
|
if not os.path.isdir(file):
|
|
ext = os.path.splitext(file)[-1][1:]
|
|
with open(dir_path+"/"+file) as fp:
|
|
count = len(fp.readlines())
|
|
if ext in res:
|
|
res[ext] += count
|
|
else:
|
|
res[ext] = count
|
|
|
|
print('统计结果如下: ')
|
|
for k, v in res.items():
|
|
print(f'{k}有: {v}行。')
|
|
|
|
|