[Python-Dev] Relative vs. absolute imports

Michael Chermside mcherm at mcherm.com
Wed May 19 20:38:43 EDT 2004


Phillip Eby:
> Yes it is, actually.  You can answer the "print foo" question simply by
> inspecting the code of the function that contains it.  (And if it's not
> in a function, you know it's a global, unless it's never assigned, in
> which case it's a builtin.)
>
> But the "import foo" question cannot be answered by referring to the
> source of the module in which it occurs.

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. 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!"

-- Michael Chermside




More information about the Python-Dev mailing list