__version__, etc. should be placed after the module docstring but before any import statements except
from __future__imports. Python mandates that future-imports must appear in the module before any other code except docstrings:
withstatement in Python is used in exception handling to make the code cleaner and much more readable. It simplifies the management of common resources like file streams.
withstatement itself ensures proper acquisition and release of resources. An exception during the
file.write()call in the first implementation can prevent the file from closing properly which may introduce several bugs in the code, i.e. many changes in files do not go into effect until the file is properly closed.
withstatement makes the code compact and much more readable. Thus,
withstatement helps avoiding bugs and leaks by ensuring that a resource is properly released when the code using the resource is completely executed. The
withstatement is popularly used with file streams, as shown above and with Locks, sockets, subprocesses and telnets etc.