Hi, I would be grateful for any assistance with the questions below in relation
ID: 3781581 • Letter: H
Question
Hi, I would be grateful for any assistance with the questions below in relation to a Python programming question. Thanks
Consider the following lines
h = httplib2.Http(".cache")
speech_headers, speech = h.request(SPEECH_URL)
stopwords_headers, stopwords = h.request(STOPWORDS_URL)
(i) What is the purpose of ".cache"?
(ii) If the request method returned a status of “304” in its Response object, what would this mean? Is it helpful or useful?
(iii) The request method returns two objects. One is a Response object. What is the data type of the other? Briefly outline, in the context of the program, what you would need to do to the speech object to make it useful after it has been created in the line speech_headers, speech = h.request(SPEECH_URL)
Explanation / Answer
Answer1.
h = httplib2.Http(".cache")
By the documentation of httplib2:
“If 'cache' is a string then it is used as a directory name for a disk cache. Otherwise it must be an object that supports the same interface as FileCache.”
Above code will create instance of Htpp() class and set cache parameter to “.cache”
Meaning that a “.cache” directory in the current working directory is used for cached data
Answer2.
If the client has performed a conditional GET request (with the If-Modified-Since or If-None-Match header) and access is allowed, but the document has not been modified, the server SHOULD respond with this status code.
Answer3.
The return value is a tuple of (response, content), the first being and instance of the ‘Response’ class, the second being a string that contains the response entity body.
(<class 'httplib2.Response'>, <class 'bytes'>)
Context of program:
May be SPEECH_URL have contains the speech given by any person so we want to analyse the speech and maybe we want to know the subject of speech or about what they are talking.
We need to parse the speech object to get useful information from the content
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.