question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing SRT data with leading whitespace

See original GitHub issue

Hi,

Platform: Windows 7 64-bit Python version: 3.7.3 64-bit Library version: 1.11.0

I am trying to parse this file (./demo.srt) with the following code:

import srt

with open(r"demo.srt") as fd:
    subs = srt.parse(fd)
    for line in subs:
        print(line)

I receive the following error:

D:\test_srt>d:/test_srt/venv/Scripts/activate.bat

(venv) D:\test_srt>d:/test_srt/venv/Scripts/python.exe d:/test_srt/demo.py
Traceback (most recent call last):
  File "d:/test_srt/demo.py", line 5, in <module>
    for line in subs:
  File "d:\test_srt\venv\lib\site-packages\srt.py", line 341, in parse
    _raise_if_not_contiguous(srt, expected_start, actual_start)
  File "d:\test_srt\venv\lib\site-packages\srt.py", line 377, in _raise_if_not_contiguous
    raise SRTParseError(expected_start, actual_start, unmatched_content)
srt.SRTParseError: Expected contiguous start of match or end of input at char 0, but started at char 2 (unmatched content: '\n\n')

pysrt handles this file without any problems. POEdit is working with it as well. So, I guess, srt is valid.

Would be thankful if you take a look at this and thanks for your work.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
JafarAbbas33commented, Dec 15, 2020

Yes, you are right. Sorry. By the way for someone having the same problem, they can use something like: with open(fname, encoding='utf-8-sig') as f:

1reaction
cdowncommented, Jul 25, 2019

0d7e5fdf8237007910d2392ae98b03041aec2d75 adds support for this. I’ll merge once CI passes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preserving leading white space while reading>>writing a file ...
First, the whitespace-trimming problem: the read command automatically trims leading and trailing whitespace; this can be fixed by changing its definition ...
Read more >
C program to trim leading white spaces from String
Iterate through given string and find the index(say idx) at which the leading space character ends. Iterate through all the characters from ...
Read more >
trimws: Remove Leading/Trailing Whitespace - Rdrr.io
a character string specifying whether to remove both leading and trailing whitespace (default), or only leading ( "left" ) or trailing ( "right"...
Read more >
Why does my shell script choke on whitespace or other ...
Leading and trailing whitespace disappears from input lines. Sometimes, when the input contains one of the characters \[*? , they are replaced ...
Read more >
Parsing Numeric Strings in .NET - Microsoft Learn
Trailing white space is permitted. NumberStyles.AllowLeadingSign, A positive or negative sign can precede numeric digits. NumberStyles.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found