Python: avoiding fraction simplification
Posted
by Anthony Labarre
on Stack Overflow
See other posts from Stack Overflow
or by Anthony Labarre
Published on 2010-05-19T06:15:27Z
Indexed on
2010/05/19
6:20 UTC
Read the original article
Hit count: 293
Hi all,
I'm working on a music app' in Python and would like to use the fractions module to handle time signatures amongst other things. My problem is that fractions get simplified, i.e.:
>>> from fractions import Fraction
>>> x = Fraction(4, 4)
>>> x
Fraction(1, 1)
However, it is important from a musical point of view that 4/4 stays 4/4 even though it equals 1. Is there any built-in way to avoid that behaviour?
Thanks!
© Stack Overflow or respective owner