DEV Community

Discussion on: Pythonic code: the with statement

jhermann profile image
Jürgen Hermann • Edited on

Using bare excepts in a series on pythonic code‽ 😁

The last example should IMHO show how to pass an object to the context, i.e. how to use yield something / with … as …:. You could smuggle in inspect.currentframe() and extend it to print "praise from {file}:{line}".

mblayman profile image
Matt Layman Author

Ha, that's fair. I was focusing on with so I didn't want to muddy the example with specific exception classes, but I agree that I probably should have put something better in there.

This series is aimed pretty squarely at newer Python developers so I've tried to avoid more complex scenarios and give a gentle introduction to with since people may have never seen anything like it in their language of choice.