I would like to take a text document that contains Feet+Frames values and convert them to Timecodes. For example, 0000+00 is replaced with 00:00:00:00.
I have a function to do the conversion from Feet+Frames to Timecode (16 frames per foot, framerate is 24 frames per second):
def FeetFramesToTimecode(FeetFrames):
frames = int(FeetFrames[:4])*16+int(FeetFrames[-2:])
return "%02d:%02d:%02d:%02d" % (frames/(3600*framerate), frames/(60*framerate)%60, frames/framerate%60, frames%framerate)
And then I have code that goes through the text file and sub's the Feet+Frame with timecode:
for line in input_document:
found = re.search(r'\d{4}\+\d{2}', line)
if found:
print "%s replaces %s" % (FeetFramesToTimecode(found.group()), found.group())
new_line = re.sub(r'\d{4}\+\d{2}', (FeetFramesToTimecode(found.group()), line)
output_document.write(new_line)
else:
output_document.write(line)
So, what am I doing wrong? How do I get a function to work inside of a re.sub?
CamelCasefor classes and usewords_separated_by_underscoresfor function names. (i.e.def feet_frames_to_time_code(feet_frames)). This makes it much clearer what is going on. (Notice how your question highlights the CamelCase differently then the rest of the code?)