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


Groups > comp.lang.python > #20155

Re: when to use import statements in the header, when to use import statements in the blocks where they are used?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <arnodel@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'imports': 0.07; 'subject:when': 0.07; 'tries': 0.15; 'subject: \n ': 0.16; 'subject:import': 0.16; 'subject:used': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; 'file,': 0.21; 'received:209.85.210.174': 0.21; 'received:mail- iy0-f174.google.com': 0.21; 'header:In-Reply-To:1': 0.22; 'subject:use': 0.24; 'cc:2**0': 0.26; 'all,': 0.27; 'function': 0.27; 'import': 0.27; 'message-id:@mail.gmail.com': 0.29; 'importing': 0.29; 'cc:addr:python.org': 0.29; 'header,': 0.30; '(e.g.': 0.31; 'subject:?': 0.31; 'received:google.com': 0.37; 'received:209.85': 0.38; 'cases,': 0.38; 'some': 0.38; 'problems': 0.38; 'aside': 0.39; 'received:209': 0.39; 'lei': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=L+xMHQikdLbmAjPk6hf9icpo0vmdivF2f3I1/iZfBb8=; b=Ieax+9OHj51uslBP4hugU3sIJ37OfsbSrKEQw8cu1JdgQfekyPIqKQN7DxpMaEC5+l FdeT2SP1JGuslrmuT+ysGCi487cN8iR4MK2Bj0H11DbydYV0e+R6hqHIOOgFSFeoITtW SfQ9IUaFphMhSQyYuV2/YYY3k6yMT14zhkOqQ=
MIME-Version 1.0
In-Reply-To <CACUCHEBhLhCCLL3OOudBKnuD2BZJvDkYzjmoi_nsVR+JPzEENA@mail.gmail.com>
References <CACUCHEBhLhCCLL3OOudBKnuD2BZJvDkYzjmoi_nsVR+JPzEENA@mail.gmail.com>
Date Fri, 10 Feb 2012 10:46:41 +0000
Subject Re: when to use import statements in the header, when to use import statements in the blocks where they are used?
From Arnaud Delobelle <arnodel@gmail.com>
To Lei Cheng <pat.inside@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5650.1328870810.27778.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328870810 news.xs4all.nl 6889 [2001:888:2000:d::a6]:59525
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20155

Show key headers only | View raw


On 8 February 2012 01:48, Lei Cheng <pat.inside@gmail.com> wrote:
> Hi all,
>
>    In a py file, when to use import statements in the header, when to use
> import statements in the blocks where they are used?
>    What are the best practices?
>    Thanks!

Aside from other answers: in some rare cases, importing within a
function can avoid circularity problems (e.g. A imports B which tries
itself to import A)

-- 
Arnaud

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


Thread

Re: when to use import statements in the header, when to use import statements in the blocks where they are used? Arnaud Delobelle <arnodel@gmail.com> - 2012-02-10 10:46 +0000

csiph-web