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

Chris Angelico rosuav at gmail.com
Wed Dec 3 06:33:12 EST 2014


On Wed, Dec 3, 2014 at 10:27 PM, Peter Otten <__peter__ at 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.

I do like the turn-around times on this list. Although, of course,
it's entirely possible there'll be a week's worth of posts coming when
someone hits on a controversial subaspect of the question somewhere;
any volunteers? :) :)

ChrisA



More information about the Python-list mailing list