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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:23:00+00:00 2026-05-10T19:23:00+00:00

I am a little confused by the multitude of ways in which you can

  • 0

I am a little confused by the multitude of ways in which you can import modules in Python.

import X import X as Y from A import B 

I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and why. Should imports happen at a module level or a method/function level? In the __init__.py or in the module code itself?

My question is not really answered by ‘Python packages – import by class, not file‘ although it is obviously related.

  • 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. 2026-05-10T19:23:01+00:00Added an answer on May 10, 2026 at 7:23 pm

    In production code in our company, we try to follow the following rules.

    We place imports at the beginning of the file, right after the main file’s docstring, e.g.:

    ''' Registry related functionality. ''' import wx # ... 

    Now, if we import a class that is one of few in the imported module, we import the name directly, so that in the code we only have to use the last part, e.g.:

    from RegistryController import RegistryController from ui.windows.lists import ListCtrl, DynamicListCtrl 

    There are modules, however, that contain dozens of classes, e.g. list of all possible exceptions. Then we import the module itself and reference to it in the code:

    from main.core import Exceptions # ... raise Exceptions.FileNotFound() 

    We use the import X as Y as rarely as possible, because it makes searching for usage of a particular module or class difficult. Sometimes, however, you have to use it if you wish to import two classes that have the same name, but exist in different modules, e.g.:

    from Queue import Queue from main.core.MessageQueue import Queue as MessageQueue 

    As a general rule, we don’t do imports inside methods — they simply make code slower and less readable. Some may find this a good way to easily resolve cyclic imports problem, but a better solution is code reorganization.

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

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You cannot bind to a null value by design in… May 11, 2026 at 11:32 am
  • added an answer In my opinion, only one good reason: you need interoperability… May 11, 2026 at 11:32 am
  • added an answer I don't follow your question, but maybe I can help… May 11, 2026 at 11:32 am

Related Questions

I am a little confused by the multitude of ways in which you can
I am a little confused as to the definition of classes as Models or
I am a little confused here. I would like to do something like this:
I am getting a little confused and need some help please. Take these two
I am a little curious about the cute little kaleidoscopic images associated with each
I am a little curious to know about how OpenID authentication works. Is there
I am a little concerned with the amount of resources that I can use
I am currently teaching myself about various data strutures and am a little frustrated
I am pretty new to the Unity Application Block and am a little stuck
I am reading over the K&R book, and am a little stuck. What is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.