使用spyder库将所有变量保存到spydata文件中

时间:2017-08-09 09:16:58

标签: python-3.x spyder

当我从python 2.7切换到python 3.3时,我遇到了一个问题。我使用了spyderlib,但现在它升级为spyder。因此,我修改了我的代码,将所有变量保存到spydata数据中,如下所示:

from spyder.utils.iofuncs import save_dictionary
def variablesfilter():
    from spyder.widgets.variableexplorer.utils import globalsfilter
    from spyder.plugins.variableexplorer import VariableExplorer
    from spyder.config.base import get_conf_path, get_supported_types

    data = globals()
    settings = VariableExplorer.get_settings()

    get_supported_types()
    data = globalsfilter(data,                   
                         check_all=True,
                         filters=tuple(get_supported_types()['picklable']),
                         exclude_private=settings['exclude_private'],
                         exclude_uppercase=settings['exclude_uppercase'],
                         exclude_capitalized=settings['exclude_capitalized'],
                         exclude_unsupported=settings['exclude_unsupported'],
                         excluded_names=settings['excluded_names']+['settings','In'])
    return data

def saveglobals(filename):
    data = variablesfilter()
    save_dictionary(data,filename)


savepath = 'memory.spydata'
saveglobals(savepath) 

然而,它会引发我们的错误,如下所示:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jialiang.shen\AppData\Local\Continuum\Anaconda3_new\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)
  File "C:\Users\jialiang.shen\AppData\Local\Continuum\Anaconda3_new\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)
  File "C:/Users/jialiang.shen/temp/s1.py", line 37, in <module>
    saveglobals(savepath) 
  File "C:/Users/jialiang.shen/temp/s1.py", line 32, in saveglobals
    data = variablesfilter()
  File "C:/Users/jialiang.shen/temp/s1.py", line 18, in variablesfilter
    settings = VariableExplorer.get_settings()
TypeError: get_settings() missing 1 required positional argument: 'self'

此错误应源于将spyderlib库升级到spyder。任何人都可以帮助我吗?非常感谢!

1 个答案:

答案 0 :(得分:0)

我认为你必须实例化VariableExplorer类:

settings = VariableExplorer(None).get_settings()