Message389158
Usually, constructors try to accept format returned by repr(obj), or even str(obj). It's the case for Fraction:
>>> str(fractions.Fraction(1, 2))
'1/2'
>>> fractions.Fraction("1/2")
Fraction(1, 2)
It works as expected.
I dislike the idea of trying to handle more Unicode characters which "look like" "/", or characters like "⅔". It sounds like a can of worm, and I don't think that such feature belongs to the stdlib. You can easily write your helper function accepting string and returning a fraction.
If someone is motivated to accept more character, I would prefer to have an unified proposition covering all Python number types (int, float, Fraction, complex, etc.) and listing all characters. Maybe a PEP would make sense. |
|
Date |
User |
Action |
Args |
2021-03-20 14:41:27 | vstinner | set | recipients:
+ vstinner, rhettinger, terry.reedy, mark.dickinson, ezio.melotti, serhiy.storchaka, weightwatchers-carlanderson |
2021-03-20 14:41:27 | vstinner | set | messageid: <1616251287.8.0.603906849027.issue43520@roundup.psfhosted.org> |
2021-03-20 14:41:27 | vstinner | link | issue43520 messages |
2021-03-20 14:41:27 | vstinner | create | |
|