我使用的解析器,從文本文件中讀取並返回這樣的類型的字典:複製類型的字典到一個新的字典,蟒蛇
{'m/z array': array([ 345.1, 370.2, 460.2, 1673.3, 1674. , 1675.3]),
'charge array': array([ 3, 2, 1, 1, 1, 1]),
'params': {'username': 'Lou Scene', 'useremail': '[email protected]',
'mods': 'Carbamidomethyl (C)', 'itolu': 'Da', 'title': 'Spectrum 2',
'rtinseconds': '25', 'itol': '1', 'charge':`enter code here` '2+ and 3+',
'mass': 'Monoisotopic', 'it_mods': 'Oxidation (M)',
'pepmass': (1084.9, 1234.0),
'com': 'Based on http://www.matrixscience.com/help/data_file_help.html',
'scans': '3'},
'intensity array': array([ 237., 128., 108., 1007., 974., 79.])}
我想讀取整個文件(所有類型的字典)並將它們存儲在一個對象中傳遞給第二個函數,以便腳本不必每次都從文件讀取(這非常緩慢)。我希望保留數據的原始結構,同時傳遞數據以便於訪問。做這個的最好方式是什麼?
我嘗試使用下面的代碼:
print ('enter mgf file name')
mgf_file = str(raw_input())
from pyteomics import mgf
reader = []
with mgf.read(mgf_file) as temp_read:
for things in temp_read:
reader.update(things)
compo_reader(reader)
你在使用什麼語法分析器?使用它的代碼是什麼樣的? – abarnert
您仍然需要向我們展示您的代碼,而不是讓我們閱讀文檔並嘗試猜測您可能使用該庫編寫的代碼。請參閱[MCVE](http://stackoverflow.com/help/mcve)獲取更多幫助,以獲取更好的問題。 – abarnert
對不起!我是這個網站和編程的新手,仍在學習如何正確執行此操作。我編輯了我原來的帖子。感謝您的迴應。 – kkhatri99