2017-08-09 2989 views
0

我從python 2.7切換到python 3.3時遇到了一個問題。我用spyderlib,但現在升級到spyder。因此,我已經修改了我的代碼將所有變量保存到下面一個spydata數據:使用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。任何人都可以幫助我嗎?非常感謝!

回答

0

我認爲你必須實例VariableExplorer類:

settings = VariableExplorer(None).get_settings() 
+0

我已經試過這種方法,但之後我做了這個變化蟒蛇得到墜毀。有什麼想法嗎? – David

相關問題