A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-September/068826.html below:

[Python-Dev] New relative import issue

[Python-Dev] New relative import issueNick Coghlan ncoghlan at gmail.com
Mon Sep 18 13:25:03 CEST 2006
Fabio Zadrozny wrote:
> I've been playing with the new features and there's one thing about
> the new relative import that I find a little strange and I'm not sure
> this was intended...
> 
> When you do a from . import xxx, it will always fail if you're in a
> top-level module, and when executing any module, the directory of the
> module will automatically go into the pythonpath, thus making all the
> relative imports in that structure fail.

Correct. Relative imports are based on __name__ and don't work properly if 
__name__ does not properly reflect the module's position in the package 
hierarchy (usually because the module is the main module, so name is set to 
'__main__').

This is noted briefly in PEP 328 [1], with the current workarounds explained 
in more detail in PEP 338 [2].

Cheers,
Nick.

[1]
http://www.python.org/dev/peps/pep-0328/#relative-imports-and-name

[2]
http://www.python.org/dev/peps/pep-0338/#import-statements-and-the-main-module

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4