fname = './新建文件夹/yob2010.txt' //文件夹路径
with open(fname,'r+',encoding='utf-8') as f:
for line in f.readlines(): //按行读取每行
print(line[:-1].split(',')) //切片去掉换行符,再以‘,'分割字符串 ,得到一个列表
s = [i[:-1].split(',') for i in f.readlines()] //列表生成器,将文件每行数据按上述方法处理后放入列表
# print(s)
txt, i= {}, 1
path = "C:\Users\THINK\Desktop\3.ini"
f = open(path,encoding='utf-8')
for line in f:
# print(line)
txt[i] = line
i += 1
txt.update(txt)
print(txt)
f.close()
# for context in txt.items():
# print(context)
f = open(path,'w',encoding='utf-8')
for k,v in txt.items():
f.write(str(k)+'= '+v)