python读写文件
来源:互联网 发布:linux关闭tomcat报错 编辑:程序博客网 时间:2024/06/07 01:09
#coding:utf8def isalary(): with open(u"F:/file1.txt","r") as fp,open(u"information.txt","w") as fi:
#获取文件的内容 可以直接f=fp.readlines不用下一步 f = fp.read()
#将读取的数据分割放在列表里 f =f.splitlines() for one in f:
#先将每一行去空格 one = one.strip()
#如果是空行,跳过本次循环 if one == "": continue if one.count(";") != 1: continue
#将字符串分割,获取字段 namepart,salarypart = one.split(";") salary = int(salarypart.split(":")[1].strip()) name = namepart.split(":")[1].strip() tax = int(salary*0.1) incom = int(salary*0.9)
#写进文件的时候必须加换行符 co = "name : %-10s,salary : %-10s,tax : %-10d, incom : %-10d\n"%(name,salary,tax,incom) fi.write(co)isalary()
阅读全文
0 0
- python--python读写文件
- Python读写Unicode文件
- python Ini文件读写
- Python读写文件
- Python读写文件
- Python读写ini文件
- Python读写文件
- Python读写文件
- Python文件的读写
- python读写文件
- python文件读写
- [Python]读写文件方法
- python 文件读写操作
- Python文件读写操作
- Python读写文件
- python之读写文件
- python读写文件
- python文件的读写
- Android 全局捕获异常
- Java笔试知识点一
- 二叉搜索树的操作题集
- react 中render与return 之间的变量(画红的问题)
- 基于概率论的分类方法:朴素贝叶斯
- python读写文件
- 《从零开始写Javaweb框架》知识点--dispatcherServlet
- 并发编程(12)-Master-Worker
- M2 | JDBC—jdbc查询:select * from 表名
- C++中的cin函数和异常的来源(failbit)与处理(clear)
- 兼容IE老版本的动态增加例子
- Mybatis逆向工程Generator
- 结合协同过滤和个性化AGENT的增强推荐(续)
- 《Web接口开发与自动化测试基于Python语言》--第14章