Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'importing': 0.04; 'subject:Python': 0.05; 'python': 0.09; 'lookup': 0.09; 'subject:modules': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mean,': 0.16; 'module?': 0.16; 'operator.': 0.16; 'program?': 0.16; 'wrote:': 0.17; 'module,': 0.17; 'jan': 0.18; 'module': 0.19; 'trying': 0.21; 'import': 0.21; 'object.': 0.22; '15,': 0.23; 'header:In-Reply-To:1': 0.25; 'creating': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'record': 0.28; "they'll": 0.29; 'probably': 0.29; 'more,': 0.32; 'affects': 0.33; 'picking': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'modules': 0.36; 'test': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'within': 0.64; 'it!': 0.64; 'fact,': 0.69; '2013': 0.84; 'thing,': 0.84; 'careful': 0.91; 'more?': 0.91 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:to :content-type; bh=lTFFspP1cJNv37cSudBhoGPZBgrkfN4YeJn7di15Q1o=; b=tvMfo3NZ22Naqw+djO1z8xrfMDc+WhboH3M1qaI83NOE2g1USCOp6TFVGOPggOwq7W PQZuorIHlohIELoX7PObHFyBcowZe8nM6iz9Uuqh8PRxz3r+suKSnPYD7OeW7kfVNOpq SA6ECqH7R/gYgCcm0l9Zr2trgYw2mbKz2WYPQgvLYBvD8akCMnTvhPYwaCeB2HDSXGzn ZEFhvYVQAcOPd+v6hCCMj4DbhMY83tkmiwUqMBkAW4nmwUzDYRNddGhkRuP+w6Lr9k1Y Q67SG8OCtS5vUwk9yuCS8BuD+kVr/ABzoQspPYjxFJRm+akz7wwoxDGWPXs6zyofyXWj yGpQ== MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 15 Jan 2013 02:04:00 +1100 Subject: Re: Python modules From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358175849 news.xs4all.nl 6896 [2001:888:2000:d::a6]:38458 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36794 On Tue, Jan 15, 2013 at 1:54 AM, zoom wrote: > Is there any "rules" regarding importing python modules within your own > module? I mean, how does this affects the performance of the program? > > In short, when creating a module, is it worthwhile to be careful and import > only necessary functions, nothing more? Nope. When you import a module, a record of it is kept in sys.modules, so the next time you import it, it's just picking up the same module object. > scipy.r_[a] = sound.scipy.r_[a] They'll actually be the same thing, which you can test with the 'is' operator. The performance cost of reimporting a module is very low; in fact, trying to avoid it by adorning all your usage with an extra dot-level will probably cost you a lot more, since there'll be an extra lookup every time. Have at it! :) ChrisA