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

def list_projects(folders, folder = None, user = None):
    '''List all folders or all subfolders of a folder.

    If folder is provided, this method will output a list of subfolders
    contained by it.  Otherwise, a list of all top-level folders is produced.

    :param folders: reference to folder.Folders instance
    :param folder: folder name or None
    :param user: optional user name

    '''
    fid = None if folder is None else Folders.name_to_id(folder)

    # List all folders if none provided.
    if fid is None:
        for f in folders.folders(user):
            print(Folders.id_to_name(f))

        return

    # List subfolders of a specific folder
    try:
        for sid in folders.subfolders(fid, user):
            print(Folders.id_to_name(sid))
    except KeyError:
        print("E: folder not found: %s" %folder, file=sys.stderr)