import os file='bsw.txt' f=open(file,'r') ff=f.read<a href="https://www.gaodaima.com/tag/line" title="查看更多关于line的文章" target="_blank">line</a>s() for line in ff: line=line.rstrip(" ") print line
www#gaodaima.com来源gaodai$ma#com搞$$代**码)网搞代码
使用strip()函数去掉每行结束的
。
strip()函数原型:
声明:str为字符串,chars为要删除的字符序列
str.strip(chars):删除s字符串中开头、结尾处,位于chars删除序列的字符
str.lstrip(chars):删除s字符串中开头处,位于chars删除序列的字符
str.rstrip(chars):删除s字符串中结尾处,位于chars删除序列的字符
更多Python知识请关注搞代码网。
来源:搞代码网:原文地址:https://www.gaodaima.com