概述
例子:
1:www.uoften.com
2:www.uoften.com
3:www.uoften.com
4:www.uoften.com
5:www.uoften.com
6:www.uoften.com
7:www.uoften.com
8:www.uoften.com
9:www.uoften.com
10:www.uoften.com
11:www.uoften.com
12:www.uoften.com
13:www.uoften.com
14:www.uoften.com
15:www.uoften.com
16:www.uoften.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。
最后
以上就是开朗航空为你收集整理的python奇偶行分开存储实现代码的全部内容,希望文章能够帮你解决python奇偶行分开存储实现代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复