Is there a Python equivalent / pseudo-equivalent to java\'s OutputStream or PrintWriter?
I want to be able to have a handle that represents either a stream like stdo
you just need an object that implements the methods that files, pipes, streams, etc... also implement. for instance, i use this class sometimes when i want to detach my python program and i want to redirect sys.stderr/sys.stdout:
class Log(object):
"""used for logging for background process"""
def __init__(self, f):
self.f = f
def write(self, s):
self.f.write(s)
self.f.flush()
sys.stdout = sys.stderr = Log(open('/tmp/daemonlog', 'a+'))