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


Groups > comp.lang.python > #76935

Re: Working with decimals

References (1 earlier) <ek0iv9diq2io1126te9j5pppoilstfuvdo@4ax.com> <CAN1F8qXtRbPiQ_W93iFLcaxT40B2uoeg_aZ8aYYhQvP7FCShqQ@mail.gmail.com> <CAPTjJmq26CwkwWE_32_C9CKXFsfnE1bb-jwW7dE2HkZ6EyW40Q@mail.gmail.com> <CAN1F8qUnUWk06uBXe0D-0V1HBuhM7j_Pxcqgb4y61kvh7ioygA@mail.gmail.com> <CAPTjJmpRwPj2huRNAFWzbCPT5PAJga6ORC96PKo2EQ7hedozOg@mail.gmail.com>
From Joshua Landau <joshua@landau.ws>
Date 2014-08-24 20:12 +0100
Subject Re: Working with decimals
Newsgroups comp.lang.python
Message-ID <mailman.13379.1408907584.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 23 August 2014 23:53, Chris Angelico <rosuav@gmail.com> wrote:
> On Sun, Aug 24, 2014 at 8:47 AM, Joshua Landau <joshua@landau.ws> wrote:
>> On 23 August 2014 23:31, Chris Angelico <rosuav@gmail.com> wrote:
>>> 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.

>>> python -c "import time; a = time.time(); import math; b = time.time(); print(b-a)"
0.0005981922149658203

*squints eyes*

Is math not already imported by start-up?

>>> 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!

FWIW, I haven't seen something that does so.

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


Thread

Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 13:47 -0400
  Re: Working with decimals Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-23 14:21 -0400
    Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 15:07 -0400
      Re: Working with decimals Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-23 15:22 -0400
      Re: Working with decimals Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-23 20:24 +0100
        Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 15:48 -0400
          Re: Working with decimals Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-23 21:31 +0100
  Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 17:13 -0400
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-23 22:47 +0100
    Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-24 08:31 +1000
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-23 23:47 +0100
    Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-24 08:53 +1000
    Re: Working with decimals Larry Hudson <orgnut@yahoo.com> - 2014-08-24 00:04 -0700
      Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-24 10:58 -0400
      Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-24 11:12 -0400
        Re: Working with decimals Larry Hudson <orgnut@yahoo.com> - 2014-08-24 14:24 -0700
          Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-24 19:07 -0400
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:12 +0100
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:17 -0600
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:19 -0600
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:25 +0100
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:29 +0100
      Re: Working with decimals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-25 12:16 +1000
        Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-25 12:27 +1000
          Re: Working with decimals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-25 12:51 +1000
            Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-25 13:01 +1000
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:37 -0600
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:40 -0600
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:49 +0100
  Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-23 22:52 +0100
    Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 18:03 -0400

csiph-web