首页 > 编程 > Python > 正文

python奇偶行分开存储实现代码

2019-11-25 15:04:03
字体:
来源:转载
供稿:网友

例子:

1:www.VeVB.COm
2:www.VeVB.COm
3:www.VeVB.COm
4:www.VeVB.COm
5:www.VeVB.COm
6:www.VeVB.COm
7:www.VeVB.COm
8:www.VeVB.COm
9:www.VeVB.COm
10:www.VeVB.COm
11:www.VeVB.COm
12:www.VeVB.COm
13:www.VeVB.COm
14:www.VeVB.COm
15:www.VeVB.COm
16:www.VeVB.COm

python函数代码

# -*- coding: utf-8 -*-'''python读取文件,偶数行输出一个文件,奇数行输出一个文件'''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中%代表什么意思

求模运算,相当于mod,也就是计算除法的余数,比如5%3就得到2。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表