fnew = open('./file/fwrite.txt','w') # 创建一个txt写入数据
def concatAB(path):
with open(path,'r',encoding='utf-8') as f:
content = f.readlines()
# ['str1\n',..]
for line in content:
line = line.strip('\n')
line = line.strip('|')
line = line.strip() # 去掉首位空格
line_ = 'curl "http://...task_id=' + line + '"'
fnew.write(line_ + '\n')
concatAB('./file/str_file.txt')
一个小细节:
假如每个字符串是| 12345678abc |,因为每一行都有字符串,在读取时每个字符串的结尾都有换行符\n,我们要去掉首位的|的话,需要先去掉\n,然后去掉|,最后去掉空格。
如果按行写入,在每次写入时都要加换行符。