New submission from Raymond Hettinger <[EMAIL PROTECTED]>: 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. ---------- components: Library (Lib) files: from_any.diff keywords: patch messages: 69264 nosy: rhettinger severity: normal status: open title: Fraction.from_any() type: feature request versions: Python 2.6, Python 3.0 Added file: http://bugs.python.org/file10810/from_any.diff _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3285> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com