msg316026 - (view) |
Author: Gabe Appleton (gappleto97) * |
Date: 2018-05-01 22:39 |
Currently it has a __repr__() which returns `Fraction(x, y)`, and a __str__() which returns `x/y`. I have a ready pull request to change this to a scheme where both return unicode fractions. |
|
|
msg316027 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2018-05-01 22:52 |
Your patch would break the usual and useful behavior of x == eval(repr(x)) >>> f = Fraction(1,2) >>> repr(f) 'Fraction(1, 2)' >>> eval(repr(f)) Fraction(1, 2) >>> f == eval(repr(f)) True Plus, I'm sure there's working code that would break as a result of this. I'd suggest having a utility function that provides the functionality that you're after. |
|
|
msg316028 - (view) |
Author: Gabe Appleton (gappleto97) * |
Date: 2018-05-01 22:54 |
Would it be workable if I instead just changed the __str__() method? I'm willing to go either way, but I feel like it's a bit nicer to have it output a nice fraction that way. |
|
|
msg316029 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2018-05-01 23:06 |
I'd bring it up on python-ideas, and point the discussion to this issue. I think the primary complain will be using non-ASCII characters in a function that normally doesn't return non-ASCII. But maybe people will be willing to accept it. |
|
|
msg316030 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2018-05-01 23:23 |
I vote -1. It's cute, but I'd much rather have a consistently ascii representation of something that is easily represented in ascii. |
|
|
msg316034 - (view) |
Author: Steven D'Aprano (steven.daprano) *  |
Date: 2018-05-02 01:44 |
Strings in Python 3 are already unicode. Looking at the patch, I see a lot of fractions which display as the missing glyph white square. For example, instead of seeing 1/9, which displays perfectly everywhere, I see a mysterious box similar to □. Even when I see one, there's the visual inconsistency between fractions which display like ½ and those that display like ¹²/₄₅ which frankly just looks ugly to me. One problem is that in many fonts, the glyphs for superscript and subscript digits are a hodge-podge of sizes and styles with no consistent design. If you're going to do this, you ought to use U+2044 FRACTION SLASH rather than U+002F SOLIDUS: compare ¹²⁄₄₅ with the above. If your font is decent, and many are not, the fraction slash is tighter and allows the numerator and denominator to overlap the slash, closer to the visual look of ½. I would strongly oppose this becoming the default __str__ of fractions. |
|
|
msg316050 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2018-05-02 07:17 |
-1 from me. Apart from anything else, the output for a general fraction looks (to my eyes) ugly in a fixed-width font: the tiny digits are harder to read, and there's too much space between successive numerator (or denominator) digits: those digits are designed for superscripts or subscripts. |
|
|
msg316076 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2018-05-02 14:49 |
In the Monaco font, the superscripts ⁰¹²³⁴⁵⁶⁷⁸⁹ don't all line-up. The 1, 2, and 3 are lower which makes the fraction look weird. |
|
|
msg316077 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2018-05-02 14:54 |
I dislike using non-ASCII characters for the default implementation. I don't think that this formatting is popular, and I expect many troubles on each platform. IMHO it's very easy to put such short function in your favorite module, or directly into your application, for your own usage. Call it my_nice_fraction_formatting() :-) |
|
|
msg316080 - (view) |
Author: Tim Peters (tim.peters) *  |
Date: 2018-05-02 16:08 |
-1. We should stop pretending this _ might_ happen ;-) |
|
|