This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
| Author | rhettinger |
|---|---|
| Recipients | rhettinger |
| Date | 2008年07月04日.19:36:25 |
| SpamBayes Score | 0.09846424 |
| Marked as misclassified | No |
| Message-id | <1215200187.54.0.0352827858842.issue3285@psf.upfronthosting.co.za> |
| In-reply-to |
| Content | |
|---|---|
After exercising the fractions module, I've found it problematic that there isn't a unified constructor to handle mixed data input types. For example, when updating the accurate summation recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090 to show how it could be done with rational arithmetic. Handling mixed-type inputs required writing a factory function: def makefrac(x): if isinstance(x, Decimal): return Fraction.from_decimal(x) if isinstance(x, float): return Fraction.from_float(x) return Fraction(x) That function supported a clean version of the recipe: def frsum(iterable): return float(sum(map(makefrac, iterable))) It would have been much better if that functionality were built into the class definition. See attached patch. |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008年07月04日 19:36:27 | rhettinger | set | spambayes_score: 0.0984642 -> 0.09846424 recipients: + rhettinger |
| 2008年07月04日 19:36:27 | rhettinger | set | spambayes_score: 0.0984642 -> 0.0984642 messageid: <1215200187.54.0.0352827858842.issue3285@psf.upfronthosting.co.za> |
| 2008年07月04日 19:36:26 | rhettinger | link | issue3285 messages |
| 2008年07月04日 19:36:26 | rhettinger | create | |