我有:
from urlparse import urlparse
s = "http://google.com" + "\n" # this line is read from file, when I loop over file's lines
urlparse(s)
ParseResult(scheme='http', netloc='google.com\n', path='', params='', query='', fragment='')这是正确的吗?不应该在解析过程中删除"\n“吗?或者我只是错误地使用了这个函数,或者我遗漏了一些实参/参数?
发布于 2012-12-14 19:33:43
在分析文本行时,始终使用str.rstrip()删除尾随的CRLF。在您的情况下,这也会对您有所帮助:
for line in open('file.txt'):
line = line.rstrip() # strip the trailing CRLF
# do what you need with the linehttps://stackoverflow.com/questions/13877761
复制相似问题