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: 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: References: 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 To: Lei Cheng 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 8 February 2012 01:48, Lei Cheng wrote: > Hi all, > > =C2=A0 =C2=A0In a py file, when to use import statements in the header, w= hen to use > import statements in the blocks where they are used? > =C2=A0 =C2=A0What are the best practices? > =C2=A0 =C2=A0Thanks! 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) --=20 Arnaud