pythons相当于PHP的文件(fn,FILE
这个问题在这里已经有了答案:
在逐行读取文件时,通常将新行字符追加到行的末尾,就像循环它一样。 如果你想摆脱它们?
with open('filename.txt', 'r') as f:
for line in f:
line = line.strip('n')
#do things with the stripped line!
这与(在Python中)相同:
with open("file.txt", "r") as f:
for line in f:
line = line.rstrip("n")
...
你要这个:
with open('filename.txt', 'r') as f:
data = [line.replace('n', '') for line in f]
链接地址: http://www.djcxy.com/p/42357.html