Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: avoiding fraction simplification

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!

like image 322
Anthony Labarre Avatar asked Dec 18 '22 00:12

Anthony Labarre


1 Answers

Yes: make a custom class for it.

Musical time signatures are not fractions, so it doesn't make sense to represent them with a math class.

like image 129
Andrew McGregor Avatar answered Jan 06 '23 13:01

Andrew McGregor