我有一个非常简单的问题:哪种方法可以用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