Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'formatting': 0.09; 'oh,': 0.09; 'spec': 0.09; 'sure,': 0.09; 'cc:addr:python-list': 0.11; '(there': 0.16; '24,': 0.16; 'called,': 0.16; 'dig': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function),': 0.16; 'function;': 0.16; 'rounding': 0.16; 'wrote:': 0.18; 'meant': 0.20; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'dramatic': 0.31; 'file': 0.32; 'critical': 0.32; 'another': 0.32; "i'd": 0.34; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'should': 0.36; 'too': 0.37; 'performance': 0.37; 'anything': 0.39; 'august': 0.61; 'you.': 0.62; 'times': 0.62; 'improvement.': 0.68; 'cuts': 0.84; 'to:none': 0.92; 'hoist': 0.93 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=gHYgsRisyAy6/wOlYVhPptj+UdXIi0rL9KV0XGtHwkg=; b=VemEvEbMdA1IVz2M8F2WkR5e0tCTv0BHsMffLXZJX4pnmpZXt8eb6jElnMGeGy0DhJ 9w5euve+ecIYfBSkfCrZEdmcZC8RSSPA1t2tikVGuqXtbU5RFCAl4V65tfq0XIM4mqhG gFnJNOJaJ2MXUf5Kjzx/VYU0iO8XvfDI7LgwhYnx3eY9V1Sn725HeTPjbnuzUVbIXVjy ryfr3Xv/7I7BtFXH8KuDVszNG+Qa0+rjn8zBo2Ta7dfryFiRYgpQ8FUlbn3Z6DkCGiaY ngxiMALDaIxFlerLGYudqUdLwfwmAB3CLGCVxmythuJ5BpGRofcOnWZxx93U72kCei1F Qd4w== MIME-Version: 1.0 X-Received: by 10.50.30.72 with SMTP id q8mr6789924igh.14.1408834432664; Sat, 23 Aug 2014 15:53:52 -0700 (PDT) In-Reply-To: References: Date: Sun, 24 Aug 2014 08:53:52 +1000 Subject: Re: Working with decimals From: Chris Angelico Cc: python-list 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408834894 news.xs4all.nl 2872 [2001:888:2000:d::a6]:32900 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76913 On Sun, Aug 24, 2014 at 8:47 AM, Joshua Landau wrote: > On 23 August 2014 23:31, Chris Angelico wrote: >> On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau wrote: >>> So for one "import math" should never go inside a function; you should >>> hoist it to the top of the file with all the other imports. >> >> I'd say "never" is too strong (there are times when it's right to put >> an import inside a function), but yes, in this case it should really >> be at the top of the function. > > But do any of them apply to "import math"? Yep. If you have only one function that will ever use it, and that function often won't ever be called, then putting the import inside the function speeds up startup. Anything that cuts down on I/O can give a dramatic performance improvement. Oh, and when I said "top of the function", what I really meant was "top of the file", but I think (hope!) people figured that out. Sorry for the braino. >> However, you won't need the import at all if you let the formatting >> function do the rounding for you. > > Can that floor? I'm not sure, dig into the format spec and see! But was flooring actually a critical part of the problem, or is another sort of rounding just as good? ChrisA