文件
注意空行!
def csv1():
""" 按行进行倒序排列;"""
f = open("data.txt", "r")
s = f.readlines()
s.reverse()
f.close()
f = open("newdata1.txt", "w")
for line in s:
f.write(line)
f.close()
pass
def csv2():
""" 每行数据倒序排列;"""
f1 = open("data.txt", "r")
s = f1.readlines()
f1.close()
f2 = open("newdata2.txt", "w")
for line in s:
f2.write(line[::-1])
f2.close()
pass
def csv3():
""" 使用分号(;)代替逗号(,)分割数据,无空格;"""
f1 = open("data.txt", "r")
s = f1.readlines()
f1.close()
f2 = open("newdata3.txt", "w")
for line in s:
t = line.replace(",", ';')
t = t.replace(' ', '')
f2.write(t)
f2.close()
pass
def cvs4():
""" 综合"""
f = open('data.txt', 'r')
lines = f.readlines()
lines.reverse()
f.close()
f2 = open("newdata4.txt", "w")
for line in lines:
line = line.replace(' ', '')
line = line.replace(",", ';')
f2.write(line[::-1])
f2.close()
if __name__ == '__main__':
cvs4()