spyder - clear variable explorer along with variables from memory

白昼怎懂夜的黑 提交于 2019-11-30 07:19:00

In Spyder, Do following steps
Run
Configuration per file...
Clear all variables before execution [Select Checkbox]

This actually clears variables from previous run of the file. Hope it helps.

Go to the IPython console in the Spyder IDE and type %reset. It will prompt you to enter (y/n) as the variables once deleted cannot be retrieved. Type 'y' and hit enter. That's it.

Surfing on the web, I found a hack to solve the annoying problem of clearing the variable explorer every time you want to execute again a script:

def clear_all():
    """Clears all the variables from the workspace of the spyder application."""
    gl = globals().copy()
    for var in gl:
        if var[0] == '_': continue
        if 'func' in str(globals()[var]): continue
        if 'module' in str(globals()[var]): continue

        del globals()[var]
if __name__ == "__main__":
    clear_all()
    # insert here your code

Basically, it consists of executing the function clear_all() just before everything else. It is writing by yourself the same Matlab's function. Here the link to the git issue where the solution was proposed.

As explained in the answer provided by Karan Kaw, there is a setting to delete all the variables, regardless of the script you are workin on.

Do the following (from the drop-downs bar)

> Tools > Preferences > Run

and check the Remove all the variables before execution checkbox in the General Setting section. In doing this I use Spyder 3.3.4.

This completion may be in order if you want all the scripts you work on to be executed with the preventive deletion of all the variables. Hope it helps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!