STINNER Victor <[email protected]> added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43520>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com