[Python-Dev] Re: Proposal for a modified import mechanism.
Gordon McMillan
gmcm@hypernet.com
Mon, 12 Nov 2001 17:17:19 -0500
Jeremy wrote:
[relative and recursively-relative imports]
> I'd rather see the imports be explicit "import root.a.b.c" than
> "import b.c". Then re-nesting requires all the import statements
> to be edited. It's more typing and might even require a simple
> script to do search-and-replace, but it doesn't sound like a
> prohibitive burden.
As a (minor) data point, if "b.c" is resolved as a relative import,
it will be faster than the absolute form ("import a.b.c").
Having re-arranged a number of packages, I have some
sympathy for Prabhu's complaint. OTOH, this is a feature
which only helps package authors (not package users, who
are likely to have a somewhat harder time finding their way
around the package).
[Prabhu]
> PR> from pkg import subpkg is also not the best way to do
> imports. I PR> personally prefer import pkg.subpkg and I
> believe this is the PR> recommended way of doing imports.
[Jeremy]
> Why do you think this is the recommended way of doing imports? I
> use both in my code and haven't been able to come up with a clear
> rationale for doing one or the other. The from ... import form
> seems useful when the name of the package/module is long or when
> it's only one or two names I'm using.
When you have circular imports, someone must use the
"import a.b.c" form. This can show up in some surprising
ways, especially when the package in question desparately
needs re-arranging <wink>.
- Gordon