Gregory Ewing <greg.ew...@canterbury.ac.nz> writes:

> sohcahto...@gmail.com wrote:
> > Now, I've noticed people talking about importing os.path.  Is there any
> > reason to use "import os.path" rather than "import os"?  Both of them will
> > still put the "os" module into the global namespace.
>
> In the case of os.path it doesn't matter, because the
> os module imports the appropriate path module automatically.

My position is that behaviour violates one of the principles of the Zen
of Python: “Special cases aren't special enough to break the rules.”

> But in general, importing a package won't necessarily
> import submodules under it, so sometimes you need to
> import somepackage.somemodule explicitly.

Because that's normally the case, I choose not to rely on that special
behaviour of ‘os’. If I need ‘os.path’, I import it explicitly so no
reader needs to guess::

    import os
    import os.path

-- 
 \       “Crime is contagious… if the government becomes a lawbreaker, |
  `\          it breeds contempt for the law.” —Justice Louis Brandeis |
_o__)                                                                  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to