처음으로 파이썬 프로그램을 작성했습니다. 로컬 폴더에 저장된 우편물에 zip 파일을 첨부합니다. 프로그램은 새 파일이 있는지 확인하고 파일이 있으면 zip 파일을 추출하고 파일 이름을 기반으로 다른 폴더로 추출합니다. 내 코드를 실행할 때 다음 오류가 발생합니다." 'NoneType'개체가 반복 가능하지 않습니다."오류
Traceback (최근 호출 마지막) : 파일 "C : /Zip/zipauto.py", 28 행, new_files의 파일 : TypeError : 'NoneType'개체 iterable이 아닙니다
아무도 내가 잘못 가고있는 곳을 말해 줄 수 있습니까?
시간 내 주셔서 감사 많은,
나빈 여기 내 코드입니다 :
import zipfile
import os
ROOT_DIR = 'C://Zip//Zipped//'
destinationPath1 = "C://Zip//Extracted1//"
destinationPath2 = "C://Zip//Extracted2//"
def check_for_new_files(path=ROOT_DIR):
new_files=[]
for file in os.listdir(path):
print "New file found ... ", file
def process_file(file):
sourceZip = zipfile.ZipFile(file, 'r')
for filename in sourceZip.namelist():
if filename.startswith("xx") and filename.endswith(".csv"):
sourceZip.extract(filename, destinationPath1)
elif filename.startswith("yy") and filename.endswith(".csv"):
sourceZip.extract(filename, destinationPath2)
sourceZip.close()
if __name__=="__main__":
while True:
new_files=check_for_new_files(ROOT_DIR)
for file in new_files: # fails here
print "Unzipping files ... ", file
process_file(ROOT_DIR+"/"+file)
aha..that 해결해 주셔서 감사합니다. – Navin