Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6736619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:09:05+00:00 2026-05-26T11:09:05+00:00

Just wrote my first python program! I get zip files as attachment in mail

  • 0

Just wrote my first python program! I get zip files as attachment in mail which is saved in local folder. The program checks if there is any new file and if there is one it extracts the zip file and based on the filename it extracts to different folder. When i run my code i get the following error:

Traceback (most recent call last): File “C:/Zip/zipauto.py”, line 28, in for file in new_files: TypeError: ‘NoneType’ object is not iterable

Can anyone please tell me where i am going wrong.

Thanks a lot for your time,

Navin
Here is my code:

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:09:06+00:00Added an answer on May 26, 2026 at 11:09 am

    check_for_new_files has no return statement, and therefore implicitely returns None. Therefore,

    new_files=check_for_new_files(ROOT_DIR)
    

    sets new_files to None, and you cannot iterate over None.

    Return the read files in check_for_new_files:

    def check_for_new_files(path=ROOT_DIR):
        new_files = os.listdir(path)
        for file in new_files:
            print "New file found ... ", file
        return new_files
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just wrote my first Python program and it works! It is a program
I've just created my first VIM script, I wrote it in Python. It's a
I just wrote my first web service so lets make the assumption that my
It's a GUI program I wrote in python checking website/server status running on my
All, I've just started using Python (v 2.7.1) and one of my first programs
I have a small python program I wrote for a friend, one of the
I'm trying to write a python program in which the program guesses the users
I just started with python and wrote myself a nice, small script that uses
I'm just about to write my first application in a duck typed language (Groovy).
Have had to write my first proper multithreaded coded recently, and realised just how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.