我想采取一个文本文档,其中包含英尺+帧值,并将它们转换为时间码。例如,0000+00将替换为00:00:00:00。你知道吗
我有一个函数来完成从英尺+帧到时间码的转换(每英尺16帧,帧速率是每秒24帧):
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)
然后我有代码,通过文本文件和sub的脚+帧的时间码:
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)
那么,我做错了什么?如何让函数在回复sub?你知道吗
您的示例代码有一个不属于您的额外的“(”。这条线应该是这样的:
这给我带来了你想要的结果。你知道吗
resub
可以接受可调用字符串的第二个参数,而不仅仅是替换字符串。你知道吗如果传递一个callable,它必须接受match对象。你知道吗
您还应该遵循python pep8使python更具可读性(对于其他pythonistas)
比如:
相关问题 更多 >
编程相关推荐