Is there any way to format a with statement so that I can establish a variable number of contexts? Like, sometimes I want four with statements, but other times I might only want two. As it is, I'm faced with the prospect of calling dummy versions of all the objects I could be using but aren't, then nesting my code in sixteen with statements with the dummy objects filling with statements I'm not using. Since I'm using Python 2.6.6 and don't even have support for the compacted syntax.
As an aside, are with statements really the only way to get cleanup code that works? There's really no other way to get anything that resembles a destructor method but isn't a mistake to use like the standard __del__
method?