记录main.py调用另一个python文件的直接引用函数方法

2025-04-05 11:41:05 6 分享链接 开发笔记 python

main.py

from merge import merge_srt_files

# 示例调用
if __name__ == "__main__":
    input_files = ["file1.srt", "file2.srt"]
    output_file = "merged.srt"
    merge_srt_files(input_files, output_file)

merge.py

import os
from datetime import datetime, timedelta

def parse_time(time_str):
    return datetime.strptime(time_str, '%H:%M:%S,%f')

def merge_srt_files(input_files, output_file):
    print(input_files)
    print(output_file)
    time_line = "00:00:03,813 --> 00:00:04,943"
    start_time_str, end_time_str = time_line.split(' --> ')
    try:
        print(parse_time(start_time_str))
        print(end_time_str)
        print(timedelta())
    except ValueError as e:
        print(f"解析时间时出错: {e}, 时间字符串: {time_line}")

记录main.py调用另一个python文件的直接引用函数方法