Was this import behaviour planned...?

Pierre Fortin pfortin at pfortin.com
Thu Jun 21 00:04:06 EDT 2001


Gordon McMillan wrote:
> 
> Pierre Fortin wrote:
> 
> >The core question:  if "import foo.bar.baz" really means
> >"foo/bar/baz...", shouldn't import ignore any files such as ./foo.py,
> >foo/bar.py, etc....?
> 
> But it doesn't. It means "find something in foo named bar, then find
> something in that named baz". foo/bar/baz.py is just one implementation,
> and it requires foo/__init__.py and foo/bar/__init__.py. But foo.bar could
> be a module, and baz an object in foo.bar, or even worse.

Bummer....  this is not quite it either 'cuz Python prefers foo.py even if
bar.baz does not exist therein, ignoring the valid stuff in foo/bar/baz...

Guess we'll need to ensure there is no <name>.py next to .../<name>/...

Thanks,
Pierre

> Or maybe they're modules, but not in your filesystem.
> 
> Planned? No way. Packages were introduced after someone hacked them up with
> a module name "ni" and lots of people started using it 'cause one flat
> namespace was just too restrictive.
> 
> - Gordon



More information about the Python-list mailing list