我需要处理一个BIG文本文件,其中包含用空格分隔的浮点数并以ASCII表示:
1.0012 0.63 18.201 -0.7911 92.2869 ...
如何使用内置的Python工具逐个读取这些数字(不是整个文件,也不是逐行读取)?示例中,用于解决此任务的C源代码如下:
float number;
FILE *f = fopen ("bigfile.txt", "rt");
while (!feof (f)) {
fscanf (f, "%f", &number);
/* ... processing the number here ... */
}
fclose (f);