I'm a first time programmer, first time StackOverflow user, studying from Allen Downey's free online text "Think Python".
The code shown here is from exercise 14.5 (p.143). I've been trying to figure out what that .fp does; my searches all came up empty. I ran the code both with and without it and didn't notice any difference in the results. I'd appreciate anyone's help on this.
import urllib
conn = urllib.urlopen('http://thinkpython.com/secret.html')
for line in conn.fp:
print line.strip()
It's just a faux file object attached to a socket object.
Read the docstring:
>>> help(conn.fp)
urllib.urlopen returns a Request object, which has .fp (file pointer) as a property. By default, the Request object when iterated over uses the same pointer, so there's no functional difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With