Message265418
| Author |
steven.daprano |
| Recipients |
amaury.forgeotdarc, asvetlov, eric.araujo, ncoghlan, pitrou, rbcollins, rhettinger, scott_daniels, steven.daprano, tshepang, vstinner |
| Date |
2016年05月12日.16:49:28 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<20160512164921.GF12028@ando.pearwood.info> |
| In-reply-to |
<1463028598.38.0.991195359239.issue6422@psf.upfronthosting.co.za> |
| Content |
On Thu, May 12, 2016 at 04:49:59AM +0000, Nick Coghlan wrote:
> The embedded side-effects were my main concern with Scott's original
> patch, so Steven's callback-based approach strikes me as a definite
> improvement. However, the awkwardness of the revised calling code in
> main does make me wonder whether or not this might be better
> implemented as a generator rather than as a function accepting a
> callback:
I thought about a generator too, but then I thought about the *non*
verbose case, where you don't care about the intermediate results, only
the final (number, time_taken) pair.
# function with callback:
number, time_taken = t.autorange()
# generator
number, time_taken = list(t.autorange())[-1]
Which hints that your code snippet is buggy, or at least incomplete:
> try:
> results = list(t.autorange())
> except:
> t.print_exc()
> return 1
> if verbose:
> for number, time_taken in results:
> msg = "{} loops -> {:.{}g} secs"
> print(msg.format(number, time_taken, precision))
If verbose is False, you never set number and time_taken. So you need an
else clause:
else:
number, time_taken = results[-1] |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2016年05月12日 16:49:28 | steven.daprano | set | recipients:
+ steven.daprano, rhettinger, scott_daniels, amaury.forgeotdarc, ncoghlan, pitrou, vstinner, rbcollins, eric.araujo, asvetlov, tshepang |
| 2016年05月12日 16:49:28 | steven.daprano | link | issue6422 messages |
| 2016年05月12日 16:49:28 | steven.daprano | create |
|