python处理txt文件的若干脚本

Posted wuyi_all_in

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python处理txt文件的若干脚本相关的知识,希望对你有一定的参考价值。


读取txt文件,将每行添加若干字符串,再写入到txt中


import numpy as np

#逐行读txt文件,并统一每行加字符串"_aligned."
with open("./1_test.txt") as txt:
content = txt.readlines() #读全部行
txt.close()
lines =np.array(content) #转换成array 类型
num_of_instances = lines.size #整个txt的行数
print("number of instances: ", num_of_instances)
list=[]
for i in range(0,num_of_instances):
line=lines[i]
list.append("./mouth/"+line)

with open("./test.txt", w)as F:
F.writelines(list)#写入到txt文件中
print(list)
F.close()

 

以上是关于python处理txt文件的若干脚本的主要内容,如果未能解决你的问题,请参考以下文章

python取txt文件的若干行到另一个文件

python小白 求助 读取txt文件,并进行数据处理

数字IC验证进阶以一个实例,快速上手python脚本处理log的若干关键操作(#python#正则表达式)

数字IC验证进阶以一个实例,快速上手python脚本处理log的若干关键操作(#python#正则表达式)

利用python处理txt文件

处理大量 .txt 文件(和整体大尺寸)的提示 - python?