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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:34:32+00:00 2026-05-13T06:34:32+00:00

I have two related Python ‘import’ questions. They are easily testable, but I want

  • 0

I have two related Python ‘import’ questions. They are easily testable, but I want answers that are language-defined and not implementation-specific, and I’m also interested in style/convention, so I’m asking here instead.

1)

If module A imports module B, and module B imports module C, can code in module A reference module C without an explicit import? If so, am I correct in assuming this is bad practice?

2)

If I import module A.B.C, does that import modules A and A.B as well? If so, is it by convention better to explicitly import A; import A.B; import A.B.C?

  • 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-13T06:34:32+00:00Added an answer on May 13, 2026 at 6:34 am

    The first thing you should know is that the Python language is NOT an ISO standard. This is rather different from C/C++, and it means that there’s no “proper” way to define a language behaviour – CPython might do something just because it was coded that way, and Jython might do the other way round.

    about your questions, remember that “importing” a module is a two-part operation: first the module is loaded – if it had never been, e.g. if it wasn’t available in sys.modules, then a name is bound to that module in the local namespace.

    hence:

    1) Yes, you can reference whatever you want from module a by providing the proper namespace, e.g. you’ll have to do something like

    B.C.name = “something”

    And I think this is very rarely done in Python programs and could be considered bad practice since it forces a “transitive dep” – if some module B implementation is refactored and doesn’t depend on C anymore, it should continue offering the C module just for satisfying A deps.

    Of course setting __ all __ can prevent this, and a good practice may be to put __ all __ in all your modules, and export just the symbols you want to be really public.

    2) Yes and no. Doing

    import a.b.c.d 
    

    performs the first import phase (loading) on all modules, but the second just on a (and, recursively, in b with respect to c, etc) but all the modules in the chain must be referenced by full namespace; after such an import, you can do

    a.something
    a.b.something
    a.b.c.something
    

    but you can’t do

    c.something
    b.something
    

    I must admit that kind of usage is pretty rare as well; I generally prefer the “from module import something” way-to-import, and generally you just ask for what you need – such nesting is neither common in libraries, nor its usage is that common.

    Many times there’re “outer packages”, just used for organization, which hold modules with classes. It’s very likely that a, b, c above are just packages, and d is a module which truly holds classes, functions and other objects. So the proper usage would be:

    from a.b.c.d import name1, name2, name3
    

    I hope this satifies your curiosity.

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

Sidebar

Ask A Question

Stats

  • Questions 279k
  • Answers 279k
  • 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
  • Editorial Team
    Editorial Team added an answer Could it possibly be that while running under the command… May 13, 2026 at 3:29 pm
  • Editorial Team
    Editorial Team added an answer The following gets all table-rows with an id, removing all… May 13, 2026 at 3:29 pm
  • Editorial Team
    Editorial Team added an answer It's a set of quite widespread C++ libraries, they're probably… May 13, 2026 at 3:29 pm

Related Questions

I would like to be able to spawn a process in python and have
Update: This is, as I was told, no principle Python related problem, but seems
I've looked through all the related questions with two or three different titles and
I have a huge text file (~1GB) and sadly the text editor I use
I have a source code of about 500 files in about 10 directories. I

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.