class Writer:
def __init__(self, stream):
self.stream = stream
def WriteIntLn(self, n):
self.stream.write('%i\n'%n)
with open('test.txt', 'w') as off:
output = Writer(off)
output.WriteIntLn(9)
ValueError: I/O operation on closed file.