[Python] Replace incorrect timestamp [closed]

Discussão em 'Python' iniciado por Stack, Julho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am generating timestamps for a webvtt file using Google translator APIs. While for most languages, it works fine, for some languages, it gives an incorrect timestamp. Due to wrong format of timestamp, the generated vtt file does not get uploaded.

    For example, in the source file, the timestamp is as below:

    01:51.400


    However, in the generated file, Google translator inserts a comma instead of a decimal point as below:

    01:54,370


    Using Python, how can I replace all such wrong format timestamps with the correct timestamp? Below statement is giving error:

    translated = re.sub(r"\d[,]\d", r"\d.\d", translated)


    translated is the variable with the translated text.

    For other errors, I am using string.replace and that is working fine.

    Statement:

    translated = re.sub(r"\d[,]\d", r"\d.\d", translated)


    Input:

    01:54,370


    Output:

    01:54.370

    Continue reading...

Compartilhe esta Página