g = open('Staffs_2031.txt','w',encoding='utf-8')
g1 = list(g)
g1.append(b)
Python问题 出现问题报错怎么办?
读入Staffs_2030.txt,找出其中本年度考核为优秀的员工,加薪20%,薪水四舍五入后统一保留整数位。然后重新写入Staffs_2031.txt中,新旧文件的编码方式均为’utf-8’
with open('Staffs_2030.txt','r',encoding='utf-8') as f:
a=f.readlines()
for i in a:
b=i.split(',')
if b[6]=='优秀':
b[5]=round(int(b[5])+0.2*int(b[5]),0)
str1=','.join(b)
with open('Staffs_2031.txt','w',encoding='utf-8') as g:
g.append(b)
else:
str1=','.join(b)
with open('Staffs_2031.txt','w',encoding='utf-8') as g:
g.append(b)
print('已根据2030信息生成2031对应文件')
Staffs_2030.txt
工号,姓名,职位,年龄,工龄,工资,考核结果
00001,曹横,总经理,40,10,30000,优秀
00002,郑武,经理,34,8,18000,及格
00007,李飞,经理,30,7,15600,优秀
00019,张白,经理,28,6,14000,及格
00035,王柳,经理,34,4,19200,优秀
01002,张小明,职员,26,3,8000,及格
01004,李小笑,职员,25,3,10800,优秀
01006,张三,职员,25,3,8400,优秀
01009,李四,职员,23,3,5000,及格
01013,王五,职员,22,3,6000,优秀
01015,郑六,职员,21,1,4000,及格
01016,宋七,职员,21,1,4800,优秀
错误提示
Traceback (most recent call last):
File "C:\Users\lzj\Desktop\p_SalaryRaising(1).py", line 13, in
g.append(b)
AttributeError: '_io.TextIOWrapper' object has no attribute 'append'
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
1条回答
为你推荐
- Python报错原因?
- python
- 1个回答
- python的json报错
- python
- 2个回答
- python 用turtle画图运行报错、大佬门帮我看看
- python
- 2个回答
- 如何解决python报错问题??
- python
- 2个回答
- linux下python调用so文件库,报错
- python
- 9个回答
- 求大佬解决Python问题中的EOF报错问题
- python
- 1个回答
- scrapy框架问题报错?
- python
- 1个回答
- Python问题 出现问题报错怎么办?
- python
- 1个回答
- python3.8 字符串输入了中文字符 为什么没有报错
- python
- 2个回答
- python中的remove函数报错FileNotFoundError?
- Python多进程问题的报错问题
- python
- 1个回答
- list是一个空的 为空 如何防止 python 报错?IndexError: list index out of range
- python进制转换输出一直报错?
- python
- 1个回答
- python import rsa 运行报错
- python
- 4个回答
- 有关python读取txt文档的问题
- python
- 1个回答
- python3中使用pyinstaller 将文件转换成.exe文件 执行后报错问题
- python
- 2个回答
- python使用pip安装multiprocess报错
- python
- 3个回答
- python一个关于while循环的报错问题
- python
- 4个回答
- 在python中写main(args)为啥老是报错?
- python
- 4个回答
- python中引用sklearn包报错
- python
- 3个回答