Skip to content

Instantly share code, notes, and snippets.

@scottfrazer
Last active March 22, 2016 14:14
Show Gist options
  • Save scottfrazer/f8fe3cee0881c424212f to your computer and use it in GitHub Desktop.
Save scottfrazer/f8fe3cee0881c424212f to your computer and use it in GitHub Desktop.
class ExecutableTempFile:
def __init__(self, someFile):
self.theFile= someFile
def __enter__(self):
self.transLog= SecureLog( self.theFile )
return self.transLog
def __exit__( self, type, value, tb ):
if type is not None:
pass # Exception occurred
self.transLog.finalize()
self.transLog.close()
self.theFile.close()
contents = "foobar"
with ExecutableTempFile(contents) as path:
subprocess.check_call("sh " + path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment