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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:06:11+00:00 2026-06-15T01:06:11+00:00

I have following arrangement of files: python |—- main.py |—- files |—- folder1 |—-

  • 0

I have following arrangement of files:

python
|---- main.py
|---- files
      |---- folder1
            |---- a.py, a1.py, ...
      |---- folder2
            |---- b.py, b1.py, ...

I wanted to import my modules a.py and b.py to main.py. For this I used the following commands in main.py:

a = 'C:/python/files/folder1'
sys.path.insert(0, a)
from files.folder1 import *

However, I am unable to import modules from folder1 (similarly for folder2).

I get an error:

No module named files.folder1

I cannot use import command as there are many Python files in folder1, folder2, …

What am I missing here?

  • 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-06-15T01:06:12+00:00Added an answer on June 15, 2026 at 1:06 am

    When I do this in Python 2.7 I use:

    import sys
    sys.path.append('C:/python/files/folder1')
    
    import a
    import a1
    

    Here’s a hack I built to import all modules in a directory into a dictionary:

    import os
    import sys
    
    dir_of_interest = 'C:/python/files/folder1'
    modules = {}
    
    sys.path.append(dir_of_interest)
    for module in os.listdir(dir_of_interest):
        if '.py' in module and '.pyc' not in module:
            current = module.replace('.py', '')
            modules[current] = __import__(current)
    

    I just built it and it’s extremely hacky but it might be more like something you want. So, to access the module you want, instead of saying module_name.thing you would say modules["module_name"].thing

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

Sidebar

Related Questions

I have following script that executes all the .reg files in the current directory.
I have following code that creates Linq query. I've never used Linq until today
I have the following arrangement : Tomcat --EJB-invokation--> JBoss (6.0.14) (5.1.0) The two servers
I have the following (view) controller arrangement: an uitableview --(embedded in)--> navigation controller --(embedded
Have following code. object.waypoint=function () { this.uw=setInterval( function() { console.log(this); }, 200); } How
I know this is possible in other programming languages. Suppose we have the following
I have following Html file with javascript. This gives me error that testCircle is
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record
I have following div in a page (I can not modify). <div id=:0.control>Click me</div>

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.