Hi, I would be grateful for some help with the questions below. Let me know if I
ID: 3781504 • Letter: H
Question
Hi, I would be grateful for some help with the questions below. Let me know if I need to send extra info. Thanks
(a) What is the purpose of each of the following lines? #!/usr/bin/python3 import string, httplib2 What is achieved by having these in the program? (6 marks) (b) What is the purpose of the following code. ? 1 W249/607 if __name__ == ’__main__’:
main ()
(c) What is the purpose of the try ... except block? What does this achieve in the context of the overall program?
(d) 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) (e) Why are the variables, SPEECH URL and STOPWORDS URL written in uppercase text?
Explanation / Answer
As per chegg policy i will answer top 3 questions.
a) #!/usr/bin/python3 is a shebang line. It defines where the interpreter is located at. Here python3 interpreter is located in /usr/bin/python3.The operating system does not know it's a python script if you set the execution flag on the script and run it like ./script.py, unless you run it like python3 script.py or set the shebang line.
b) When python file is executed it is assigned a name. The initial file which is executed via "python abc.py" is assigned the name "main" and it is stored under the variable __name__.
c) If an exception occurs during execution of the try clause, the rest of the clause is skipped.If its type matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement.If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements; if no handler is found, it is an unhandled exception and execution stops with a message.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.