我正在运行一个 python CGI 脚本,使用 numpy 从动态创建的 CSV 中读取数据。Numpy 抱怨它找不到文件,但它在那里。从 python 脚本我可以使用 system(cat) 预先打印文件......
filename is: /tmp/file3aQJRn
Dump file with system(cat)...
A
-257
-1
-136
29567
-97
-8867
-27041
-12323
-17473
-659
Ask numpy to read it...
Traceback (most recent call last):
(some lines deleted, then...)
File "request", line 195, in get_rawcsv_column
col_data = get_csv_column(fname,column)
File "request", line 189, in get_csv_column
all_data = np.genfromtxt(fname,delimiter=",")
File "usr/lib/python3.6/site-packages/numpy/lib/npyio.py", line 1551, in genfromtxt
File "usr/lib/python3.6/site-packages/numpy/lib/_datasource.py", line 151, in open
File "usr/lib/python3.6/site-packages/numpy/lib/_datasource.py", line 501, in open
OSError: "/tmp/file3aQJRn" not found.
之后,我可以在 bash 提示符下转储文件:
# cat /tmp/file3aQJRn
A
-257
-1
-136
29567
-97
-8867
-27041
-12323
-17473
-659
我可以调用 Python (3.6) 和 numpy 来读取文件...
numpy.genfromtxt("/tmp/file3aQJRn",delimiter=",")
array([ nan, -2.57000000e+02, -1.00000000e+00,
-1.36000000e+02, 2.95670000e+04, -9.70000000e+01,
-8.86700000e+03, -2.70410000e+04, -1.23230000e+04,
-1.74730000e+04, -6.59000000e+02])
( nan 不是问题。它是随后从数组中删除的列标题。)
这里发生了什么?临时文件由 C++ 应用程序使用 std::ofstream 从 tmpnam() 获得临时文件名生成。
杨__羊羊
相关分类