您好,登錄后才能下訂單哦!
業(yè)務(wù)需求
需要將文本文件分每?jī)尚幸唤M
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
核心代碼:
# -*- coding: utf-8 -*- ''' python讀取文件,每?jī)尚袨橐唤M ''' 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")
通過執(zhí)行 python jb51.txt
o.txt的內(nèi)容
到這里這篇文章就完成了,希望大家以后多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。