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


Groups > comp.lang.python > #96325

Re: Question about import

Path csiph.com!news.mixmin.net!news2.arglkargh.de!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'exercise': 0.03; 'needed,': 0.05; 'subject:Question': 0.05; 'front,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'explicitly': 0.15; 'importing': 0.15; 'thu,': 0.15; '__init__.py': 0.16; 'input.': 0.16; 'missing?': 0.16; 'module?': 0.16; 'omitting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:n 70': 0.16; 'subject:import': 0.16; 'thought.': 0.16; 'wrote:': 0.16; 'stick': 0.18; 'project,': 0.18; '2015': 0.20; 'explicit': 0.22; 'referring': 0.22; 'sep': 0.22; 'am,': 0.23; 'wrote': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:X-Complaints-To:1': 0.26; 'wonder': 0.27; 'question': 0.27; 'module.': 0.27; "skip:' 10": 0.28; 'fine': 0.28; 'if,': 0.29; 'pep': 0.29; 'that.': 0.30; 'another': 0.32; 'useful': 0.33; 'that,': 0.34; 'could': 0.35; 'direction': 0.35; 'quite': 0.35; 'but': 0.36; 'there': 0.36; 'modules': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'say': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'one,': 0.37; 'thought': 0.37; 'names': 0.38; 'anything': 0.38; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'ever': 0.60; 'more': 0.63; 'different': 0.63; 'qualified': 0.63; 'you.': 0.64; 'reuse': 0.66; "they're": 0.66; 'situation': 0.67; 'frank': 0.72; 'overhead,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: Question about import
Date Fri, 11 Sep 2015 08:40:24 +0200
References <msrah1$sju$1@ger.gmane.org> <CALwzidm3khNaGTt0OhVEo5bhqk1tFEjBUUUinW9TNUxrpnr8cw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; format=flowed; charset="iso-8859-1"; reply-type=original
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 197.86.222.206
In-Reply-To <CALwzidm3khNaGTt0OhVEo5bhqk1tFEjBUUUinW9TNUxrpnr8cw@mail.gmail.com>
X-MSMail-Priority Normal
Importance Normal
X-Newsreader Microsoft Windows Live Mail 15.4.3502.922
X-MimeOLE Produced By Microsoft MimeOLE V15.4.3502.922
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.357.1441953656.8327.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1441953656 news.xs4all.nl 23734 [2001:888:2000:d::a6]:45358
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96325

Show key headers only | View raw


"Ian Kelly"  wrote in message 
news:CALwzidm3khNaGTt0OhVEo5bhqk1tFEjBUUUinW9TNUxrpnr8cw@mail.gmail.com...

On Thu, Sep 10, 2015 at 1:12 AM, Frank Millman <frank@chagford.com> wrote:
> > That makes me wonder if, in my project, I can import all modules inside
> > 'start.py', and then just use 'import package_name' inside each module?
>
> You can, but for readability and reuse I think it's better to be
> explicit in each module and import the fully qualified module names
> that are needed, rather than relying on some other module to import
> them for you.

I don't disagree. However, I started this exercise because I found a 
situation in one of my modules where I was referring to another module 
without ever importing it, and it worked! It took me quite a while to track 
down what was happening. So there could be a case for being explicit in the 
other direction - import all modules up front, and explicitly state that all 
modules are now free to reference anything in any other module. I will give 
it more thought.

> > Another question - I thought that, because aa.py and bb.py are in 
> > different
> > sub-directories, I would have to set them up as packages by adding
> > '__init__.py' to each one, but it works fine without that. What am I
> > missing?

> That surprises me also, but I suspect it's because they're
> subdirectories of the current working directory rather than packages
> found on the sys.path.

I had a look at PEP 420, as mentioned by Peter. I did not understand much of 
it, but it did say that omitting __init__.py incurs an additional overhead, 
so I will stick with including it.

Many thanks for the useful input.

Frank

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


Thread

Re: Question about import "Frank Millman" <frank@chagford.com> - 2015-09-11 08:40 +0200

csiph-web