Style question: Importing modules from packages - 'from' vs 'as'

Chris Angelico rosuav at gmail.com
Thu Dec 4 13:05:25 EST 2014


On Fri, Dec 5, 2014 at 4:36 AM, Jean-Michel Pichavant
<jeanmichel at sequans.com> wrote:
> I know you specifically stated you didn't want to do this but
>
> import os
>
> os.path.isfile()
>
> is the best option imo, especially from the reader point of view ("Namespaces are one honking great idea").

With os.path it definitely is. With the actual code in question, it's
a Python 2.7 project that mostly uses relative imports - inside
package.module1 is "import module2" etc - and I was writing an
external script that calls on one of the modules. So it makes sense to
reference it through the code the exact same way, as "module.blah"
rather than "package.module.blah".

ChrisA



More information about the Python-list mailing list