Python file operations homemade little Exercises

Source: Internet
Author: User
Tags readline

 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 '&gt;&gt;' 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
&gt;&gt; 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
&gt;&gt; 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
&gt;&gt; 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
&gt;&gt; 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.