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


Groups > comp.lang.python > #81951

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'lines,': 0.07; "subject:' ": 0.07; 'os.path': 0.09; 'subject:modules': 0.09; 'sure,': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '2.7': 0.14; 'mostly': 0.14; 'foo"': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imports': 0.16; 'modules.': 0.16; 'shifts': 0.16; 'top-level': 0.16; 'wrote:': 0.18; 'typing': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; '2.x': 0.24; 'certainly': 0.24; 'directory.': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'external': 0.29; 'feature': 0.29; 'am,': 0.29; 'dec': 0.30; 'relative': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'usually': 0.31; 'implicit': 0.31; 'fri,': 0.33; 'actual': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'etc': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'project': 0.37; 'question,': 0.38; 'does': 0.39; 'sure': 0.39; 'is.': 0.60; 'details': 0.65; 'to:none': 0.92
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=yzVfqBYDzzIJ78IzwbL3Mo3ONv0WLqLCyzWC7CZWMyM=; b=XTOS6F2Ajm9VyNTuInKJryLv+fEruYpBlTM4Y3Qpz7PD6EWOoEZZTQ+pdhckt4HJ4T CH0ZGaC40oNSlLyDamXswehAAUnZ8Ej0bG0R1gA+bmvi30pZ1/icOesXpOVubbGvXsUI morSXH6Ycr49NdDIKjA5vL0zQTGolJvNkwUT+K2OcOKlCX7GD26Dj4jlRpt/sbJxPI9f p0BNeSFRaSzZqyodsKkHkO+mlNxojWOz655HeCcO8YDQeQGVWJIK3hrkam0Nwzdm2h7F CeO9Ofqqu+8GKqVJFsqI+hYU5wSodyVIsE3pMkR8P4GrxsCnIPtByrMnkR8vRywS8OKA CqRw==
MIME-Version 1.0
X-Received by 10.50.61.140 with SMTP id p12mr15845430igr.34.1417728659721; Thu, 04 Dec 2014 13:30:59 -0800 (PST)
In-Reply-To <m5qhqd$bts$1@ger.gmane.org>
References <CAPTjJmo1-QCgcbsjKNgH3oN-nm5qjB5GrvCiC6Qc9p+S8cNjpg@mail.gmail.com> <2047880662.4611734.1417714597653.JavaMail.root@sequans.com> <CAPTjJmpgM2n=AdY+8gZ40gqe1S2zfD83Ui-f5SngRYLA3jMtCQ@mail.gmail.com> <m5qhqd$bts$1@ger.gmane.org>
Date Fri, 5 Dec 2014 08:30:59 +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.16589.1417728663.18130.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417728663 news.xs4all.nl 2965 [2001:888:2000:d::a6]:32977
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81951

Show key headers only | View raw


On Fri, Dec 5, 2014 at 7:56 AM, Wolfgang Maier
<wolfgang.maier@biologie.uni-freiburg.de> wrote:
> On 04.12.2014 19:05, Chris Angelico wrote:
>>
>>
>> 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.
>
>
> What ? I'm usually thinking Python 3 not 2 and I'm never sure which Python
> 2.x has backported which feature of 3, but I thought implicit relative
> imports like you seem to describe are not working in 2.7 ?

Hmm, I'm not sure, but certainly it does seem to work that way. Typing
"import foo" from inside a package will import foo.py from the package
directory. I haven't dug into the details of _why_, and if ever the
project shifts to Python 3 (which I would like it to), we might have
to change some of the import lines, but I'd still like to be able to
reference "foo.bar" as meaning the "bar" top-level object in foo.py.

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-05 08:30 +1100

csiph-web