I was trying out one of the Python standard library modules, let's call it foo.bar.baz
.
So I wrote a little script starting with
import foo.bar.baz
and saved it as foo.py
.
When I executed the script I got an ImportError. It took me a while (I'm still learning Python), but I finally realized the problem was how I named the script. Once I renamed foo.py
to something else, the problem went away.
So I understand that the import foo
statement will look for the script foo.py
before looking for the standard library foo
, but it's not clear to me what it was looking for when I said import foo.bar.baz
. Is there some way that foo.py
could have the content for that statement to make sense? And if not, why didn't the Python interpreter move on to look for a directory hierarchy like foo/bar
with the appropriate __init__.py
's?.