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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:57:53+00:00 2026-06-10T15:57:53+00:00

I don’t understand the following from pep-0404 In Python 3, implicit relative imports within

  • 0

I don’t understand the following from pep-0404

In Python 3, implicit relative imports within packages are no longer
available – only absolute imports and explicit relative imports are
supported. In addition, star imports (e.g. from x import *) are only
permitted in module level code.

What is a relative import?
In what other places star import was allowed in python2?
Please explain with examples.

  • 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-10T15:57:54+00:00Added an answer on June 10, 2026 at 3:57 pm

    Relative import happens whenever you are importing a package relative to the current script/package.

    Consider the following tree for example:

    mypkg
    ├── base.py
    └── derived.py
    

    Now, your derived.py requires something from base.py. In Python 2, you could do it like this (in derived.py):

    from base import BaseThing
    

    Python 3 no longer supports that since it’s not explicit whether you want the ‘relative’ or ‘absolute’ base. In other words, if there was a Python package named base installed in the system, you’d get the wrong one.

    Instead it requires you to use explicit imports which explicitly specify location of a module on a path-alike basis. Your derived.py would look like:

    from .base import BaseThing
    

    The leading . says ‘import base from module directory’; in other words, .base maps to ./base.py.

    Similarly, there is .. prefix which goes up the directory hierarchy like ../ (with ..mod mapping to ../mod.py), and then ... which goes two levels up (../../mod.py) and so on.

    Please however note that the relative paths listed above were relative to directory where current module (derived.py) resides in, not the current working directory.


    @BrenBarn has already explained the star import case. For completeness, I will have to say the same ;).

    For example, you need to use a few math functions but you use them only in a single function. In Python 2 you were permitted to be semi-lazy:

    def sin_degrees(x):
        from math import *
        return sin(degrees(x))
    

    Note that it already triggers a warning in Python 2:

    a.py:1: SyntaxWarning: import * only allowed at module level
      def sin_degrees(x):
    

    In modern Python 2 code you should and in Python 3 you have to do either:

    def sin_degrees(x):
        from math import sin, degrees
        return sin(degrees(x))
    

    or:

    from math import *
    
    def sin_degrees(x):
        return sin(degrees(x))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't ask me why but I need to do the following: string ClassName =
Don't think that I'm mad, I understand how php works! That being said. I
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't know where else to ask, but from one day to the other my
Don't ask me how but I managed to get accidentally the following remote branches
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't quite understand determinism in the context of concurrency and parallelism in Haskell. Some
Don't understand why #include <Header.h> is not compiling while #include Header.h is compiling with
Don't know is it possible to copy elements from one map to another map

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.