[Python-Dev] Relative vs. absolute imports

Bernhard Herzog bh at intevation.de
Thu May 20 16:15:01 EDT 2004


Michael Chermside <mcherm at mcherm.com> writes:

> Bernhard Herzog:
>> Of course it's different, but it's not all that much different.  To
>> determine whether an import is relative or not you look into the
>> directory containing the module with the import statement.  Shouldn't be
>> more than a few keystrokes in a decent editor.
>
> On the contrary, I find a big difference between something which can
> be learned by inspecting the source and something which requires
> access to the filesystem the source is running on. 

Me too, but, in the case of imports, regardless of whether they're
absolute or relative you will always have to refer to information ouside
of the module you're looking at.  In most cases you'll need to look at
the filesystem among other things.

However, telling relative and absolute imports apart is easy compared to
the difficulty of dealing with imports in general, just like telling
local and global variables apart is easy compared to the difficulty of
dealing with variables in general.  That's what I'm comparing.

> Many times that
> filesystem isn't even available: "Susan emailed me this module she
> uses to fnob large datasets, and I can't understand why it isn't
> working for me!"

Sure, but errors are always hard to find when you look at a piece of
code without access to the relevant context.  PEP 328 won't have much if
any impact on this problem.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Skencil                                http://sketch.sourceforge.net/
Thuban                                  http://thuban.intevation.org/



More information about the Python-Dev mailing list