Parsing SRT data with leading whitespace
See original GitHub issueHi,
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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
0d7e5fdf8237007910d2392ae98b03041aec2d75 adds support for this. I’ll merge once CI passes.