下面给出一个函数,用于返回其参数的大小之和(可以是单个文件/目录或文件/目录列表)。代码给出了一条错误消息RuntimeError: maximum recursion depth exceeded while calling a Python object
,但是我试图对此进行测试。
怎么解决这个问题?
谢谢
苏雷什
#!/usr/bin/python3.1
import os
def fileSizes(f):
if hasattr(f,'__iter__'):
return sum(filter(fileSizes,f))
if os.path.isfile(f):
return os.path.getsize(f)
elif os.path.isdir(f):
total_size = os.path.getsize(f)
for item in os.listdir(f):
total_size += fileSizes(os.path.join(f, item))
return total_size
目前没有回答
相关问题 更多 >
编程相关推荐