Python Urlparse和'\n';
我有:Python Urlparse和'\n';,python,urlparse,Python,Urlparse,我有: 这是正确的吗?在分析过程中不应该删除“\n”吗?或者我只是不正确地使用了这个函数,或者我缺少了一些参数?在分析文本行时,始终使用str.rstrip()删除尾部的CRLF。这也将对您的情况有所帮助: 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
这是正确的吗?在分析过程中不应该删除“\n”吗?或者我只是不正确地使用了这个函数,或者我缺少了一些参数?在分析文本行时,始终使用
str.rstrip()
删除尾部的CRLF。这也将对您的情况有所帮助:
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='')
for line in open('file.txt'):
line = line.rstrip() # strip the trailing CRLF
# do what you need with the line