Code Challenge 09 - The With Statement and Context Managers

PyBites, Mon 06 March 2017, Challenges

codechallenges, contextlib, contextmanagers, decorators, generators, learning, with

This week, each one of you has a homework assignment ... - Tyler Durden (Fight club)

A new week, time for some coding!

This week we have a free form exercise. After reading Dan's great article on the with statement we thought it would be cool to ask our PyBites community to come up with creative uses of the with statement. This week you get to implement your own Context Manager.

You can either:

Have fun!

Other resources

To follow along with our challenges

Start coding by forking our challenges repo:

$ git clone https://github.com/pybites/challenges

If you already forked it sync it:

assuming using ssh key
$ git remote add upstream git@github.com:pybites/challenges.git
$ git fetch upstream
# if not on master:
$ git checkout master
$ git merge upstream/master
$ cd 09
# open withlove.py (just a blank file for this challenge)code

Remember: there is no best solution, only learning more/ better Python. We're looking forward reviewing our and your solutions end of this week. Good luck and have fun!


About PyBites Code Challenges

More background in our first challenge article.

PyBites Python Tips

Do you want to get 250+ concise and applicable Python tips in an ebook that will cost you less than 10 bucks (future updates included), check it out here.

Get our Python Tips Book

"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H

"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B

"This is now my favourite first Python go-to reference." - Anthony L

"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S

Get the book