<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def close(num=None, figs=True, data=True, ds=True, remove_only=False):
 """ Close the project This method closes the current project (figures, data and datasets) or the project specified by `num` Parameters num: int, None or 'all' if :class:`int`, it specifies the number of the project, if None, the current subproject is closed, if ``'all'``, all open projects are closed %(Project.close.parameters)s See Also -------- Project.close"""

    kws = dict(figs=figs, data=data, ds=ds, remove_only=remove_only)
    cp_num = gcp(True).num
    got_cp = False
    if num is None:
        project = gcp()
        scp(None)
        project.close(**kws)
    elif num == 'all':
        for project in _open_projects[:]:
            project.close(**kws)
            got_cp = got_cp or project.main.num == cp_num
            del _open_projects[0]
    else:
        if isinstance(num, Project):
            project = num
        else:
            project = [project for project in _open_projects
                       if project.num == num][0]
        project.close(**kws)
        try:
            _open_projects.remove(project)
        except ValueError:
            pass
        got_cp = got_cp or project.main.num == cp_num
    if got_cp:
        if _open_projects:
            # set last opened project to the current
            scp(_open_projects[-1])
        else:
            _scp(None, True)