This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: relative import solution
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Fixpythonbugs, georg.brandl, ncoghlan, r.david.murray
Priority: normal Keywords:

Created on 2013-01-03 05:52 by Fixpythonbugs, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg178913 - (view) Author: FizzledOut (Fixpythonbugs) Date: 2013-01-03 05:52
Instead of giving the error message " Attempted relative import in non-package", simply process the line!

from . import Example

whether or not the file is __main__, it should be able to go up one directory, if possible, and try to import Example.py.  It makes no sense that this cannot be done.
msg178940 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-01-03 12:39
Could you give more information about what you see as the bug, here?  I'm not understanding the problem because there doesn't appear to be enough context.  What is your directory structure?  Where is the import happening?
msg178945 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-01-03 14:01
David, the "issue" is that Python only allows relative imports within packages.  The OP wants to have a.py and b.py in the same directory and then be able to said "from . import b" in the a module.

This is a design decision and will not change without a PEP.
History
Date User Action Args
2022-04-11 14:57:40adminsetgithub: 61050
2013-10-13 18:25:26georg.brandlsetstatus: pending -> closed
2013-01-03 14:01:05georg.brandlsetstatus: open -> pending

nosy: + georg.brandl, ncoghlan
messages: + msg178945

resolution: rejected
2013-01-03 12:39:07r.david.murraysetnosy: + r.david.murray
messages: + msg178940

components: + Interpreter Core, - Windows
type: resource usage -> behavior
2013-01-03 05:52:11Fixpythonbugscreate