下面给出了一个函数,用于返回其参数大小的总和,可以是单个文件/目录或文件/目录列表.代码给出了错误消息,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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5240 次 |
最近记录: |