def read_file(file_path="abc.txt"):file = open(file_path, "r")content = file.readlines()file.close()return content def write_file(content, file_path="abc1.txt"):file = open(file_path, "w")file.writelines(content)file.flush()file.close()if __name__ == "__main__"...
python中向文本每行行尾添加字符
def read_file(file_path="abc.txt"):
file = open(file_path, "r")
content = file.readlines()
file.close()
return content
def write_file(content, file_path="abc1.txt"):
file = open(file_path, "w")
file.writelines(content)
file.flush()
file.close()
if __name__ == "__main__":
content = read_file()
new_content = list()
for c in content:
c = c.strip()
new_content.append(c + str(int(c) - 1) + "\r\n")
write_file(new_content)2018-03-01
f = open('1.txt')
o = open('2.txt', 'w+')
for line in f:
o.write(line)
o.write(你要加的数据)2012-10-28
s = open('1.txt','r').readlines() #读取成每一行构成的列表
out=open('out.txt','w') #打开一个输出文件用以写入
n=len(s)
for i in range(n):
out.write("%s %s"%(s[i],[i])) #向输出文件中写入:第i行、数字i
out.close()2012-10-29