Livecoding.tv Quiz of the Day: 09/11/2016

Python Quiz!

python-quiz-2

Answer:

In a few words the with statement allows you to executed code before and/or after a specific set of operations. For example if you open a file for reading and parsing no matter what happens during the parsing you want to be sure that at the end the file is closed. This is normally achieved using the try… finally construction but the with statement simplifies it usin the so called “context management protocol”. To use it with your own objects you just have to define __enter__ and __exit__ methods. Some standard objects like the file object automatically support this protocol. For more information you may check Understanding Python’s “with” statement.

If you want to explore more, visit our Python edu & tutorials section! Below are some examples:

Data Science with Python

Event Management System in Python

 

-->
Read previous post:
americas-best-coding-non-profits
America’s Best Coding Non-Profits

Coding non-profits are organizations that want to improve the state of programming and computer science education, and any associated fields....

Close