Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81854

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; "subject:' ": 0.07; 'latter': 0.09; 'os.path': 0.09; 'subject:modules': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'although,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hits': 0.16; 'renaming': 0.16; "week's": 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'wed,': 0.18; '(the': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'posts': 0.26; 'header:In- Reply-To:1': 0.27; 'tim': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'entirely': 0.33; 'actual': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'possible': 0.36; 'list.': 0.37; 'pm,': 0.38; 'times': 0.62; 'more': 0.64; 'worth': 0.66; 'close': 0.67; 'repeat': 0.74; 'hand': 0.80; 'dry': 0.84; 'otten': 0.84; 'to:none': 0.92; 'yourself,': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=nRIPTNeomX1/lIYytsJSgiVDXW+hYYtJz8CdNGmUy8Y=; b=PJlI3HND578Ox4qqnJ2eMW4XlZhgKxKEIYRcTw+kNHZzVMRIuB+DTgBTxxpln6owsT 9AOzTdYoQveOOzg65j0X23WOJxV1+AwCxJ44BjMAdI0sLHgpq01lWbQ8A+9Lp1oHYeL0 AlAhtvlK9N7h1dc+AQR8B+REzxxMW1rb4GUQ7xJnm1V1jyie00C1tJVsnB4I8Sbi4rLT f1q6Aj6c34wcnC7jX4HqLLLLOB4dy/TdZ9rtnRlfsP9YONYxs1r69fABAIO/eA2fC9DQ YTyk5ix2w/6bqfJAwAgWti9QFWPAI33gswNtFUjjzUSnz68fjLv3TbxqSgZnwVUrkio5 8Wqw==
MIME-Version 1.0
X-Received by 10.50.23.48 with SMTP id j16mr46936183igf.34.1417606392582; Wed, 03 Dec 2014 03:33:12 -0800 (PST)
In-Reply-To <m5ms2d$ea0$1@ger.gmane.org>
References <CAPTjJmo1-QCgcbsjKNgH3oN-nm5qjB5GrvCiC6Qc9p+S8cNjpg@mail.gmail.com> <m5ms2d$ea0$1@ger.gmane.org>
Date Wed, 3 Dec 2014 22:33:12 +1100
Subject Re: Style question: Importing modules from packages - 'from' vs 'as'
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16529.1417606395.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417606395 news.xs4all.nl 2902 [2001:888:2000:d::a6]:34804
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 4046
X-Received-Body-CRC 2966767113
Xref csiph.com comp.lang.python:81854

Show key headers only | View raw


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.

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Style question: Importing modules from packages - 'from' vs 'as' Chris Angelico <rosuav@gmail.com> - 2014-12-03 22:33 +1100

csiph-web