forBinchRange (29): A= Open ('d:\\a\\'+ STR (b+1) +'. SRT','R')#Read Filelines = Len (A.readlines ())#number of measured file linesA.seek (0,0)#number of measured file linesc = Open ('C.txt','a')#New File ifB >0:ce='\n\nthis is Lesson'+ STR (b+1) +'\ n' #header row ifb = =0:ce='This is lesson'+ STR (b+1) +'\ n' #header rowC.write (CE) G=0 whileG <lines:e=a.readline () G+ = 1e=a.readline () G+ = 1e=a.readline () G+ = 1 while(E! ='\ n' andE! ="' ): if '>>' inche:e= E[8:] C.write (e) e=a.readline () G+ = 1a.close () c.close ( )
Goal: Extract the text part of the subtitle file
Pit, Main points:
1) Number of file lines:
lines = len (a.readlines ()) A.seek (0,0)
2) Append write mode ' a '
3) The file read to the blank line is ' \ n ', the file read to the end of the "
Example: 1.SRT
1
00:00:00,730-00:00:02,050
Hi. Welcome to Version Control.
2
00:00:02,050-00:00:04,300
I ' M Carolyn, one of your instructors for the course.
3
00:00:04,300-00:00:05,350
>> and I ' M Sarah, your other instructor.
4
00:00:05,350-00:00:08,340
In this course, we ' ll cover the concept of Version Control and
5
00:00:08,340-00:00:09,960
Why do you might want to use it.
6
00:00:09,960-00:00:12,610
>> Yeah. So, the Version Control is the sort of like have a giant undo button for
7
00:00:12,610-00:00:13,530
Your project.
8
00:00:13,530-00:00:15,720
>> You mean like this one?
Example: 3.SRT
1
00:00:00,310-00:00:01,630
Hey, I ' m here with Larry, and
2
00:00:01,630-00:00:04,019
He ' s been has a problem with
A webpage he ' s been working on.
3
00:00:04,019-00:00:06,810
I think a great opportunity to
Both help, Larry out, with his problem and
4
00:00:06,810-00:00:09,230
To show you what version
Control can is useful for.
5
00:00:09,230-00:00:10,700
>> Yeah, So,
I ' ve been working on a website, and
6
00:00:10,700-00:00:12,540
It looks a lot different
than it did before.
7
00:00:12,540-00:00:13,610
There used to BES a banner at the top.
Python file operations homemade little Exercises