def METHOD_NAME(file = None, needclose = 0):
    """Call this with an open file object to make it the output file.
    Call it without arguments to close the current file (if necessary)
    and reset it to sys.stdout.
    If the second argument is true, the new file will be explicitly closed
    on a subsequence call.
    """
    global _File, _NeedClose
    if _NeedClose:
        tmp = _File
        _NeedClose = 0
        _File = None
        tmp.close()
    if file is None:
        import sys
        file = sys.stdout
    _File = file
    _NeedClose = file and needclose