python读取文件去掉换行符

读取文件如何去掉换行符,代码如下:

f = open('filepath','r')
data = [line.strip('\n') for line in f.readlines()]

这样就可以去掉换行符啦

更多推荐

python读取文件去掉换行符