<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def opened(filename, mode):
    "Open filename, or do nothing if filename is already an open file object"
    if isinstance(filename, str):
        file = open(filename, mode)
        try: 
            yield file
        finally: 
            if not file.closed:
                file.close()
    else:
        yield filename