Last active
January 6, 2020 16:04
-
-
Save andyfcx/56d0228ab833f9a472bd5efc78413599 to your computer and use it in GitHub Desktop.
python_unittest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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