Python Questions & Answers Already
passed
Which of the following Python data structures is most similar to the value returned in this
line of Python:
x = urllib.request.urlopen('http://data.pr4e.org/romeo.txt') - ANSWERSfile handle
In this Python code, which line actually reads the data:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print(data.decode())
mysock.close() - ANSWERSmysock.recv()
Which of the following regular expressions would extract the URL from this line of
HTML:
<p>Please click <a href="http://www.dr-chuck.com">here</a></p> - ANSWERSnot
href="(.+)", http://.*
In this Python code, which line is most like the open() call to read a file:
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if (len(data) < 1):
break
print(data.decode())
mysock.close() - ANSWERSmysock.connect( )