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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:11:04+00:00 2026-06-09T16:11:04+00:00

I have this package: mypackage/ __init__.py a.py b.py And I want to import things

  • 0

I have this package:

mypackage/
    __init__.py
    a.py
    b.py

And I want to import things from module a to module b, does it make sense to write in module b

from mypackage.a import *

or should I just use

from a import *

Both options will work, I’m just wondering which is better (the 2nd makes sense because it’s in the same level but I’m considering the 1st to avoid collisions, for example if the system is running from a folder that contains a file named a.py).

  • 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-09T16:11:06+00:00Added an answer on June 9, 2026 at 4:11 pm

    You can safely use number 2 because there shouldn’t be any collisions – you’ll be always importing a module from the same package as the current one. Please note, that if your module has the same name as one of the standard library modules, it will be imported instead of the standard one. From the documentation:

    When a module named spam is imported, the interpreter first searches
    for a built-in module with that name. If not found, it then searches
    for a file named spam.py in a list of directories given by the
    variable sys.path. sys.path is initialized from these locations:

    • the directory containing the input script (or the current directory).
    • PYTHONPATH (a list of directory names, with the same syntax as the
    • shell variable PATH).
    • the installation-dependent default.

    After initialization, Python programs can modify sys.path. The
    directory containing the script being run is placed at the beginning
    of the search path, ahead of the standard library path.
    This means
    that scripts in that directory will be loaded instead of modules of
    the same name in the library directory. This is an error unless the
    replacement is intended. See section Standard Modules for more
    information.

    The option from mypackage.a import * can be used for consistency reasons all over the project. In some modules you will have to do absolute imports anyway. Thus you won’t have to think whether the module is in the same package or not and simply use a uniform style in the entire project. Additionally this approach is more reliable and predictable.

    Python style guidelines don’t recommend using relative imports:

    Relative imports for intra-package imports are highly discouraged.
    Always use the absolute package path for all imports. Even now that
    PEP 328 is fully implemented in Python 2.5, its style of explicit
    relative imports is actively discouraged; absolute imports are more
    portable and usually more readable.

    Since python 2.5 a new syntax for intra-package relative imports has been introduced. Now you can . to refer to the current module and .. referring to the module being 1 level above.

    from . import echo
    from .. import formats
    from ..filters import equalizer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a module named 'io' in my package: mypackage.io . This causes a
I have two packages. The class I want to import from the first package
I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
I have a package like this package/ __init__.py subpackage1/ __init__.py moduleA.py moduleB.py moduleC.py moduleD.py
I have a Controller defined like this: package controllers import play.api._ import play.api.mvc._ import
Say i have this this structure. MyApp ├── main.py └── package ├── __init__.py ├──
I have this folder structure: package/ __init__.py misc/ __init__.py tools.py subpackage/ __init__.py submodule.py I
I'm working on a package, and I have a structure like: mypackage/ __init__.py __main__.py
i have a java class :: package MyPackage; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet;
Say I have a package called Foo organized this way: Foo\ __init__.py foo.py bar.py

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.