On Dec 3, 2014 4:34 AM, "Chris Angelico" <ros...@gmail.com> wrote: > > On Wed, Dec 3, 2014 at 10:27 PM, Peter Otten <__pete...@web.de> wrote: > > Don't repeat yourself, so > > > > from os import path > > > > always. On the other hand I have never thought about actual renames, e. g. > > > > from os import path as stdpath > > > > versus > > > > import os.path as stdpath > > > > I think I'd use the latter as it looks simpler. > > Thanks, Peter and Tim. Keeping DRY is worth doing (the more so as it's > raining as I type this...), and I won't be renaming in this, so the > from-import wins - but as Tim says, it's a close race.
To offer a counterpoint, the from import is also less explicit. With "import os.path as path", path must be a module. With the from import, path could be either a module or just any attribute of the os module. My preference when importing modules is to use the fully qualified name -- os.path, not path. If I do a submodule import, I'm probably assigning a local name anyway, so I still prefer the "import as" over the "from import as".
-- https://mail.python.org/mailman/listinfo/python-list