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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:12:46+00:00 2026-05-13T21:12:46+00:00

In Python, what exactly does import * import? Does it import __init__.py found in

  • 0

In Python, what exactly does import * import? Does it import __init__.py found in the containing folder?

For example, is it necessary to declare from project.model import __init__, or is from project.model import * sufficient?

  • 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-13T21:12:47+00:00Added an answer on May 13, 2026 at 9:12 pm

    The “advantage” of from xyz import * as opposed to other forms of import is that it imports everything (well, almost… [see (a) below] everything) from the designated module under the current module. This allows using the various objects (variables, classes, methods…) from the imported module without prefixing them with the module’s name. For example

    >>> from math import *
    >>>pi
    3.141592653589793
    >>>sin(pi/2)
    >>>1.0
    

    This practice (of importing * into the current namespace) is however discouraged because it

    • provides the opportunity for namespace collisions (say if you had a variable name pi prior to the import)
    • may be inefficient, if the number of objects imported is big
    • doesn’t explicitly document the origin of the variable/method/class (it is nice to have this “self documentation” of the program for future visit into the code)

    Typically we therefore limit this import * practice to ad-hoc tests and the like. As pointed out by @Denilson-Sá-Maia, some libraries such as (e.g. pygame) have a sub-module where all the most commonly used constants and functions are defined and such sub-modules are effectively designed to be imported with import *. Other than with these special sub-modules, it is otherwise preferable to …:

    explicitly import a few objects only

    >>>from math import pi
    >>>pi
    >>>3.141592653589793
    >>> sin(pi/2)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'sin' is not defined
    

    or import the module under its own namespace (or an alias thereof, in particular if this is a long name, and the program references its objects many times)

      >>>import math
      >>>math.pi
      >>>3.141592653589793
      etc..
    
    
      >>>import math as m  #bad example math being so short and standard...
      >>>m.pi
      >>>3.141592653589793
      etc..
    

    See the Python documentation on this topic

    (a) Specifically, what gets imported with from xyz import * ?
    if xyz module defines an __all__ variable, it will import all the names defined in this sequence, otherwise it will import all names, except these which start with an underscore.

    Note Many libraries have sub-modules. For example the standard library urllib includes sub-modules like urllib.request, urllib.errors, urllib.response etc. A common point of confusion is that

    from urllib import *

    would import all these sub-modules. That is NOT the case: one needs to explicitly imports these separately with, say, from urllib.request import * etc. This incidentally is not specific to import *, plain import will not import sub-modules either (but of course, the * which is often a shorthand for “everything” may mislead people in thinking that all sub-modules and everything else would be imported).

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

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • 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 Just project your local list into a list of the… May 14, 2026 at 10:02 pm
  • Editorial Team
    Editorial Team added an answer The above is probably an Objective-C category that extends the… May 14, 2026 at 10:02 pm
  • Editorial Team
    Editorial Team added an answer One interesting option I've seen is to use the English… May 14, 2026 at 10:02 pm

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.