\n, \t, \\ 是特殊的 转义字符呀。。>>> with open("E:\\test\\t3.txt","r", encoding='utf-8') as f:
info=f.readlines()
print(info)
info = str(info).strip().replace("[", "").replace("]", "").replace("'", "")
print(info)
info = info.replace("\\n", "")
print(info)
['name=Tom\n', 'age=28\n', 'sex=man']
name=Tom\n, age=28\n, sex=man
name=Tom, age=28, sex=man
>>>
# 不过,为何不用 str.join(),
>>> with open('t3.txt', 'r', encoding='utf-8') as f:
info = f.readlines() # 是列表!
print(info)
print(''.join(info).replace("\\n", '--'))
['name=Tom\n', 'age=28\n', 'sex=man']
name=Tom--age=28--sex=man
|