亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python奇偶行分開存儲實現(xiàn)代碼

 更新時間:2018年03月19日 20:23:05   作者:為援不可圖  
這篇文章主要介紹了python讀取文件,偶數(shù)行輸出一個文件,奇數(shù)行輸出一個文件,需要的朋友可以參考下

例子:

1:chabaoo.cn
2:chabaoo.cn
3:chabaoo.cn
4:chabaoo.cn
5:chabaoo.cn
6:chabaoo.cn
7:chabaoo.cn
8:chabaoo.cn
9:chabaoo.cn
10:chabaoo.cn
11:chabaoo.cn
12:chabaoo.cn
13:chabaoo.cn
14:chabaoo.cn
15:chabaoo.cn
16:chabaoo.cn

python函數(shù)代碼

# -*- coding: utf-8 -*-
'''
python讀取文件,偶數(shù)行輸出一個文件,奇數(shù)行輸出一個文件
'''
def fenhang(infile,outfile,outfile1):

 infopen = open(infile,'r',encoding='utf-8')
 outopen = open(outfile,'w',encoding='utf-8')
 outopen1 = open(outfile1, 'w', encoding='utf-8')
 lines = infopen.readlines()
 i = 0
 for line in lines:
 i += 1
 if i % 2 == 0:
  outopen.write(line)
 else:
  outopen1.write(line)
 infopen.close()
 outopen.close()
fenhang("jb51.txt","oushu.txt","jishu.txt")

效果圖

python中%代表什么意思

求模運(yùn)算,相當(dāng)于mod,也就是計算除法的余數(shù),比如5%3就得到2。

相關(guān)文章

最新評論