>>> from fractions import Fraction >>> Fraction(0.25) Fraction(1, 4)

Read more of this post