with-statement

How to make a class that acts like a string?

I have a context manager that captures output to a string for a block of code indented under a with statement. This context manager yields a custom result object which will, when the block has finished executing, contain the captured output. from contextlib import contextmanager @contextmanager def capturing(): "Captures output wit...

Python with statement - is there a need for old-style file handling any more?

With having the with statement, is there ever a need to open a file/check for exceptions/do manual closing of resources, like in try: f = open('myfile.txt') for line in f: print line except IOError: print 'Could not open/read file' finally: f.close() ...

Extended With-keyword in VB.NET

In my current project everyone names variables and methods after what they are and what they do. This is good for quickly understanding the code, but with a lot of long varible names comes some headaches, such as when copying a dataset to an entity/object. So, while you understand the code, the readability still takes a blow. veryLongVa...

Is this the best way to do a "with" statement in C++?

Edit: So this question was misinterpreted to such a ludicrous degree that it has no point anymore. I don't know how, since the question that I actually asked was whether my specific implementation of thisyes, known to be pointless, yes, not remotely resembling idiomatic C++macro was as good as it could be, and whether it necessarily had...