Skip to content

Instantly share code, notes, and snippets.

@andyfcx
Last active January 6, 2020 16:04
Show Gist options
  • Save andyfcx/56d0228ab833f9a472bd5efc78413599 to your computer and use it in GitHub Desktop.
Save andyfcx/56d0228ab833f9a472bd5efc78413599 to your computer and use it in GitHub Desktop.
python_unittest
class _WritelnDecorator(object):
"""Used to decorate file-like objects with a handy 'writeln' method"""
def __init__(self,stream):
self.stream = stream
def __getattr__(self, attr):
if attr in ('stream', '__getstate__'):
raise AttributeError(attr)
return getattr(self.stream,attr)
def writeln(self, arg=None):
if arg:
self.write(arg)
self.write('\n') # text-mode streams translate to \r\n if needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment