gpt4 book ai didi

python - 如何删除 Python 中的行尾?

转载 作者:行者123 更新时间:2023-11-28 20:42:43 26 4
gpt4 key购买 nike

<分区>

我发现每次读取一行时,行尾字符也包括在内(在 vi set list 命令中显示为“$”),我想知道如何在从文件读取时自动删除它?

从打印输出可以看出每次都输出行尾,好像每次都打印两行。

这是代码和输入文件,还有输出,

import sys

fileInput = open(sys.argv[1], 'r')

for line in fileInput:
print line

python TestLineParse.py TestInput.txt.csv
216

218

219

248

head TestInput.txt.csv
216
218
219
248

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com