HttpResponseObject在读取()之后是否会更改。在python openurl方法中解码(';utf-8';)?

HttpResponseObject在读取()之后是否会更改。在python openurl方法中解码(';utf-8';)?,python,python-3.6,httpresponse,Python,Python 3.6,Httpresponse,我目前正在学习Python3,正在玩openurl,这时我注意到在read().decode('utf-8')之后,我的HTTP响应对象的长度变为零,我不明白为什么它会这样 story = urlopen('http://sixty-north.com/c/t.txt') print(story.read().decode('utf-8')) story_words = [] for line in story: line_words = line.decode('utf-8').spl

我目前正在学习Python3,正在玩openurl,这时我注意到在read().decode('utf-8')之后,我的HTTP响应对象的长度变为零,我不明白为什么它会这样

story = urlopen('http://sixty-north.com/c/t.txt')
print(story.read().decode('utf-8'))
story_words = []
for line in story:
    line_words = line.decode('utf-8').split()
    for word in line_words:
        story_words.append(word)
story.close()
print(story_words)
在第2行执行print命令时,story中HTTP响应的长度从593变为0,并且在story单词上打印一个空数组。如果删除print命令,则填充story\u单词数组

Output with read().decode()
It was the best of times
it was the worst of times
it was the age of wisdom
it was the age of foolishness
it was the epoch of belief
it was the epoch of incredulity
it was the season of Light
it was the season of Darkness
it was the spring of hope
it was the winter of despair
we had everything before us
we had nothing before us
we were all going direct to Heaven
we were all going direct the other way
in short the period was so far like the present period that some of
its noisiest authorities insisted on its being received for good or for
evil in the superlative degree of comparison only
[]

Output without it - 

['It', 'was', 'the', 'best', 'of', 'times', 'it', 'was', 'the', 'worst', 'of', 'times', 'it', 'was', 'the', 'age', 'of', 'wisdom', 'it', 'was', 'the', 'age', 'of', 'foolishness', 'it', 'was', 'the', 'epoch', 'of', 'belief', 'it', 'was', 'the', 'epoch', 'of', 'incredulity', 'it', 'was', 'the', 'season', 'of', 'Light', 'it', 'was', 'the', 'season', 'of', 'Darkness', 'it', 'was', 'the', 'spring', 'of', 'hope', 'it', 'was', 'the', 'winter', 'of', 'despair', 'we', 'had', 'everything', 'before', 'us', 'we', 'had', 'nothing', 'before', 'us', 'we', 'were', 'all', 'going', 'direct', 'to', 'Heaven', 'we', 'were', 'all', 'going', 'direct', 'the', 'other', 'way', 'in', 'short', 'the', 'period', 'was', 'so', 'far', 'like', 'the', 'present', 'period', 'that', 'some', 'of', 'its', 'noisiest', 'authorities', 'insisted', 'on', 'its', 'being', 'received', 'for', 'good', 'or', 'for', 'evil', 'in', 'the', 'superlative', 'degree', 'of', 'comparison', 'only']



调用
urlopen
返回类似文件的缓冲区对象。使用
read
可以在不传递参数的情况下获得最多若干字节的响应,或者获得整个响应,直到
EOF
。读取后,缓冲区为空。这意味着您需要在打印之前将返回的值保存在变量中。

感谢您的回复,我还注意到,如果read()被注释掉,那么在每次迭代中,缓冲区响应都会被使用,直到它为空为止。