欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

例子:

1:www.dbjr.com.cn
2:www.dbjr.com.cn
3:www.dbjr.com.cn
4:www.dbjr.com.cn
5:www.dbjr.com.cn
6:www.dbjr.com.cn
7:www.dbjr.com.cn
8:www.dbjr.com.cn
9:www.dbjr.com.cn
10:www.dbjr.com.cn
11:www.dbjr.com.cn
12:www.dbjr.com.cn
13:www.dbjr.com.cn
14:www.dbjr.com.cn
15:www.dbjr.com.cn
16:www.dbjr.com.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中%代表什么意思

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

相關(guān)文章

最新評論