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 7404113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:12:31+00:00 2026-05-29T05:12:31+00:00

I have a folder with a __init__.py File __init__.py: #!/usr/bin/python2 flags=test File main.py: #!/usr/bin/python2

  • 0

I have a folder with a __init__.py

File __init__.py:

#!/usr/bin/python2
flags="test"

File main.py:

#!/usr/bin/python2
import foldername

def main():
    print foldername.flags

if __name__ == '__main__':
main()

Now, when I run ./main.py (from inside the folder), I get the error

ImportError: No module named foldername
  • 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-29T05:12:32+00:00Added an answer on May 29, 2026 at 5:12 am

    Run from the parent folder for foldername:

        $ python -m foldername.main
    

    If you rename main.py to __main__.py then you could run it as (since Python 2.7):

        $ python -m foldername
    

    python -m adds implicitly current directory to your python path (sys.path).

    Parent Folder/
    └── foldername
        ├── __init__.py
        │   #    flags="test"
        └── __main__.py
            #    import foldername
            #   
            #    def main():
            #        print foldername.flags
            #   
            #    if __name__=="__main__":
            #        main()
    

    If the parent directory for foldername is in your python path then you could run the above commands from any directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following contents in src/main/clojure/za/co/pb/maven_test/test.clj file: (ns za.co.pb.maven-test.test (:gen-class)) (defn -main []
I have a folder, c:\websites\test , and it contains folders and files that were
I have a py file like this, which errors out. from world import acme
I have been reading about the function of __init__.py file. It is said that
I have a file in one of the folder in my documents folder .I
I have a bin/ folder with tons of Bash, Python scripts and some C
I have a folder A which contains some Python files and __init__.py. If I
I have a folder with some DLLs in it (not .NET assemblies) and I
I have an images folder with a png in it. I would like to
I have my project folder, for instance, myWeb . In it there are various

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.