단일 파일/디렉토리 또는 파일/디렉토리 목록 일 수있는 인수의 크기 합계를 반환하는 함수가 아래에 나와 있습니다. 이 코드는 오류 메시지 RuntimeError: maximum recursion depth exceeded while calling a Python object
을 표시하지만 테스트 해 보려고합니다.Python : 최대 재귀 깊이
해결 방법?
감사
수레 쉬
#!/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
listdir에 현재 디렉토리가 포함되어 있습니까? 반복하는 iterables는 무엇입니까? –
'os.listdir()'은 현재 또는 부모 디렉토리를 포함하지 않습니다. – suresh