I'm parsing a screenplay .XML file and I need to add the length in eighths of each scene. In film, the scripted length of a scene is measured in eighths and we never reduce that number. Page eighths are used for many different purposes and must remain as such.
So, as I parse my screenplay XML file, each scene heading paragraph element has a child called SceneProperties with an attribute Length the value of which is contained in a string:
<Paragraph Type="Scene Heading" Number="6">
<SceneProperties Length="1/8" Page="1" Title=""/>
What I need to do is add up the total page eighths of all the scenes in the script. There seem to be two unique aspects to this otherwise simple math: Some of the Length values have a whole number and a fraction separated by a space (like "1 2/8"), and all of the eighths need to remain as eighths. So basically I need to:
from fractions import Fraction
scene_1 = "2/8"
scene_2 = "1 4/8"
Length = Fraction(scene_1) + Fraction(scene_2)
print(Length)
#This doesn't work - I need it to print "1 6/8"
Any ideas how I would go about this?