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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:21:05+00:00 2026-05-15T15:21:05+00:00

I want to have a number of files imported in a general python file

  • 0

I want to have a number of files imported in a general python file and then include that file when I need the imported modules in the current module. This of course will lead to errors and re-imports if using the from x import y, however when using the “normal” import statement I end up with long instruction statements, for example:

x = importModule.directoryName1.directoryName2.moduleName.ClassName()

whereas I’d like to do the following:

x = importModule.ClassName()

but as I said before, doing this:

from importModule.directoryName1.directoryName2.moduleNam import ClassName

in a general file doesn’t work since I include importModule in ClassName.

So, I’m basically wondering if there’s anyway around this (something like an using statement, such as the one in C++, perhaps?)

  • 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-15T15:21:06+00:00Added an answer on May 15, 2026 at 3:21 pm

    It sounds like you’ve got recursive imports (importModule refers to moduleName, and moduleName refers to importModule. If you refactor, you should be able to use

    from importModule.directoryName1.directoryName2.moduleName import ClassName
    

    To refactor, you can change the order in which things are imported in moduleName so that the class definition of ClassName occurs before the importModule import; as long as each file defines the references needed by the other module before they try and import the other module, things will work out.

    Another way to refactor: you could always import ClassName within the function where it’s used; as long as the function isn’t called before moduleName is imported, you’ll be fine.

    The best way to refactor, though, is to move some classes or references into their own module, so you don’t have any situation where A imports B and B imports A. That will fix your problem, as well as make it easier to maintain things going forward.

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

Sidebar

Related Questions

I have a number of images and a CSV data file that I want
I have a number of CSV files of data that I want to Union
I have an arbitrary number of files that I need to load in an
I have a large number of csv files that I want to read into
i have a number of files that i want to have the same base
I have a number of CSV files that I want to download from Yahoo
I have a large number of image files that i need to rename from
Say I want to have a method that takes any kind of number, is
I have a COM project that contains a number of IDL files, some of
I have a need to import a number of CSV files into corresponding tables

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.