|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 豌图酱 于 2017-2-22 14:12 编辑
第0题统计当前目录各种类型文件数量的作业,答案其实看懂了,可是不知道自己写的代码有什么问题,麻烦大家看下:
import os
f = os.listdir(os.curdir)
temp = []
ext = []
for each in f:
(file_name,ext_) = os.path.splitext(each)
if ext_=='':
ext_='文件夹'
ext = ext.append(ext_)
for each_ext in ext:
if each_ext not in temp:
print('该文件夹下共有类型为【%s】的文件%d个'%(each_ext,ext.count(each_ext)))
temp.append(each_ext)
报错:
Traceback (most recent call last):
File "C:/Users/lenovo/Desktop/python/统计各个类型文件数.py", line 10, in <module>
ext = ext.append(ext_)
AttributeError: 'NoneType' object has no attribute 'append'
- import os
- f = os.listdir(os.curdir)
- temp = []
- ext = []
- for each in f:
- (file_name,ext_) = os.path.splitext(each)
- if ext_=='':
- ext_='文件夹'
- ext.append(ext_)
- for each_ext in ext:
- if each_ext not in temp:
- print('该文件夹下共有类型为【%s】的文件%d个'%(each_ext,ext.count(each_ext)))
- temp.append(each_ext)
复制代码
|
|