我有一個非常簡單的問題:哪種方法可以用Python從txt文件中讀取不同的條目?python從文件中讀取數據
想我也一個文本文件,如:
42017 360940084.621356 21.00 09/06/2015 13:08:04
42017 360941465.680841 29.00 09/06/2015 13:31:05
42017 360948446.517761 16.00 09/06/2015 15:27:26
42049 361133954.539315 31.00 11/06/2015 18:59:14
42062 361208584.222483 10.00 12/06/2015 15:43:04
42068 361256740.238150 19.00 13/06/2015 05:05:40
在C,我會做:
while(fscanf(file_name, "%d %lf %f %d/%d/%d %d:%d:%d", &id, &t0, &score, &day, &month, &year, &hour, &minute, &second) != EOF){...some instruction...}
什麼會做這樣的事情在Python中的最佳方式?爲了將每個值存儲到不同的變量中(因爲我必須在整個代碼中使用這些變量)。
在此先感謝!
可能重複閱讀一個大的文本文件(幾GB)](http://stackoverflow.com/questions/14944183/python-fastest-way-to-read-a-large-text-file-several-gb) – user3636636
你想取決於列的字符串列表或類型列表? – FunkySayu
你可以看看Numpy [loadtxt](http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html) – Mel