Python 2.7.14 |Anaconda, Inc.| IPython 5.4.1
I do not understand why depending on how I give the arguments to pickle, I am getting the desired result or an error Please, take a look to this example:
import urllib
import pickle
p= pickle.load(urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p"))
link='http://www.pythonchallenge.com/pc/def/banner.p'
q= pickle.load(urllib.urlopen(link))
and I get the data for p and q (list 23 elements)
However, If I try:
f = urllib.urlopen(link)
r= pickle.load(f)
I get:
raise EOFError
If I try:
myfile = f.read()
s= pickle.load(myfile)
I get:
AttributeError: 'str' object has no attribute 'readline'
I search in SO for similar solutions, but I failed to find one that could give me an answer.
Can anyone help me to understand why r and s failed, when q and f look the same to me?
******EDITED TO RESPONSE DAVIS HERRING ********
import urllib
import pickle
link="http://www.pythonchallenge.com/pc/def/banner.p"
f = urllib.urlopen(link)
#myfile = f.read()
r= pickle.load(f)
Removing myfile = f.read(), makes r to work. You were right! Now I understand your answer, I cannot read f then use it on load(). However, it looks reading f changes f?
Ok, I found an answer on this topic here