0
Does "with ... as ...:" work with non-files?
For example, this code doesn't work: with int("5") as a: print(a)
1 Answer
+ 2
Actually it works with objects, where those objects provide __enter__ and __exit__ methods.
http://effbot.org/zone/JUMP_LINK__&&__python__&&__JUMP_LINK-with-statement.htm
If you defined your own integer object with those methods, you could also 'with' them.