0
我正在將一些MATLAB代碼翻譯成Python,我需要訪問數據結構。使用SciPy的,我需要連接的用戶輸入字符串轉換爲文件名:使用連接文件名在Python中訪問MATLAB數據
cb_data = scipy.io.loadmat('./cb_data/' + subj_id + '_cb_AAAD_V2.mat' , 'rb')
其中subj_id是從用戶輸入來的變量。我也曾嘗試直接輸入用戶輸入,但它返回相同的錯誤
File "/Users/pproctor/anaconda/PythonScripts_conda/get_num_trials.py",line 36, in
get_num_trials cb_data = scipy.io.loadmat('./cb_data/' + subj_id + '_cb_AAAD_V2.mat' , 'rb')
File "/Users/pproctor/anaconda/lib/python2.7/site-packages/scipy
/io/matlab/mio.py", line 137, in loadmat mdict.update(matfile_dict)
AttributeError: 'str' object has no attribute 'update'
這是正確的解決方法,謝謝 – pproctor