Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81870
| References | <CAPTjJmo1-QCgcbsjKNgH3oN-nm5qjB5GrvCiC6Qc9p+S8cNjpg@mail.gmail.com> <m5ms2d$ea0$1@ger.gmane.org> <CAPTjJmqyZQ-YKmKGiZa0DJf52ENkNWRfuiJPbDjWUFnuDyutHg@mail.gmail.com> |
|---|---|
| Date | 2014-12-03 12:52 -0700 |
| Subject | Re: Style question: Importing modules from packages - 'from' vs 'as' |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16539.1417636348.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Dec 3, 2014 4:34 AM, "Chris Angelico" <rosuav@gmail.com> wrote: > > On Wed, Dec 3, 2014 at 10:27 PM, Peter Otten <__peter__@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".
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Style question: Importing modules from packages - 'from' vs 'as' Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-03 12:52 -0700
csiph-web