Python divides the text into two lines and saves them to the file. python has two lines.
Business Requirements
You need to divide the text file into a group of two lines.
Jb51.txt
1: www.jb51.net
2: www.jb51.net
3: www.jb51.net
4: www.jb51.net
5: www.jb51.net
6: www.jb51.net
7: www.jb51.net
8: www.jb51.net
9: www.jb51.net
10: www.jb51.net
11: www.jb51.net
12: www.jb51.net
13: www.jb51.net
14: www.jb51.net
15: www.jb51.net
16: www.jb51.net
Core code:
#-*-Coding: UTF-8-*-'''python reads files. Each of the two behaviors is a set of ''' def fenhang (infile, outfile): infopen = open (infile, 'R', encoding = 'utf-8') outopen = open (outfile, 'w', encoding = 'utf-8') lines = infopen. readlines () I = 1 for line in lines: if I % 2 = 0: outopen. write (line + '\ n') else: outopen. write (line) I + = 1 infopen. close () outopen. close () fenhang ("jb51.txt", "o.txt ")
RunPython jb51.txt
O.txt content
This article has been completed. I hope you will be able to support the customer's home in the future.