RE: [Fwd: Lament: Import is not very smart.]
"Mark Hahn" <[email protected]> Thu, 15 Jul 2004 10:59:42 -0700
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <000801c46a95$81939260$0b01a8c0@mark> |
Paul Prescod wrote: > Another Python quirk to avoid... > I don't know if this is a bug or a feature, but it sure is > annoying. I apologize if it's already been discussed to death > elsewhere (I couldn't find anything). > > Suppose that you've a package named "foo" which contains module "bar". > Because you're careless, you've also put foo/ into your path... > > Here's the problem: > > >> import foo.bar > >> import bar > >> foo.bar == bar > False > > The second import doesn't recognize that "bar" is already > loaded as foo.bar, and loads the module again. I know it's > easy to avoid this by being consistent, but wouldn't be more > intuitive if import checked a hash of loaded module filenames > before importing something anew? E.g. > > >> import foo.bar > >> import bar > >> foo.bar == bar > True > > It's probably too late to change, but it's food for thought. Isn't package also a namespace? Wouldn't this feature destroy that namespace feature?