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

  • SEARCH
  • Home
  • 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 533445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:30:33+00:00 2026-05-13T09:30:33+00:00

This is a snip-it of python I am working on right now – I

  • 0

This is a snip-it of python I am working on right now – I did not list all of this code, so I apologize if something you need is “missing” – I think I can explain it well enough without the rest of it…

Below there is a function main() – this is not explicitly defined in my script – it is imported from another script made by someone else. When it is called, it outputs a very long list of every single available module python has available to call. I am trying to add line numbers to each module. So when it outputs it’s a very long list of module names (I assume the function main() is putting “\n” breaks after each module because it prints one module, then a new line, then another module name). What I am TRYING to do is take those values, and add a line number in front of each module name.

   elif x == "list" or x == "1":

            print "\n loading... please wait"
            time.sleep(2)
            counter=0

            lnumber = 0
            all_mods = (main())

            for x in all_mods: 
                print lnumber, x
                lnumber = lnumber + 1
                counter = counter + 1

            print "-" * 30, "\nTotal number of modules detected: ", counter

**I understand the lnumber and counter are reporting the same thing, however I did this on purpose because it is consistent with the code I have elsewhere in the document which did not use this setup.

When this snippet of code is ran (with the other parts of the script) it reports back:

Traceback (most recent call last):
  File "C:\Users\jc\Documents\Python Projects\Projects\myOwnfns\helpwiz.py", line 131, in <module>
    main_loop()
  File "C:\Users\jc\Documents\Python Projects\Projects\myOwnfns\helpwiz.py", line 90, in main_loop
    for x in all_mods: #this variable comes from "list_all_mods" - an external script taken from another author.
TypeError: 'NoneType' object is not iterable
  • 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-13T09:30:34+00:00Added an answer on May 13, 2026 at 9:30 am

    The function main prints the lines to standard output; it doesn’t return anything. More precisely it returns the None object, so all_mods is None. That’s the cause for “‘NoneType’ object is not iterable”, because you’re trying to iterate over it with for x in all_mods.

    Here’s a terribly hackish solution that will work:

    import sys, StringIO
    buffer = StringIO.StringIO()
    sys.stdout = buffer
    main()
    buffer.seek(0)
    all_mods = buffer.read().splitlines()
    sys.stdout = sys.__stdout__
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.