RE: [Python-Dev] Relative vs. absolute imports
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
Michael Chermside
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/
participants (2)
-
Bernhard Herzog
-
Michael Chermside