1

我正在使用 astropy.table.write(filename, path=run_dir) 将 astropy 表写入名为 dat.h5 的文件。但是我收到了文件存在的错误,我在下面显示了它不存在的 pdb 跟踪。到底是怎么回事?

(Pdb) run_dir
'/Users/ms/run0'

(Pdb) os.system("ls " + run_dir)
param.txt    temp_in.dat  temp_out.dat
0

(Pdb) os.path.exists(run_dir + '/dat.h5')
False

(Pdb) dat_cube.write('dat.h5', format='hdf5', path=run_dir)
*** IOError: File exists: dat.h5
4

1 回答 1

2

path变量是hdf5 文件中的一个路径(请参阅http://docs.astropy.org/en/stable/api/astropy.io.misc.hdf5.write_table_hdf5.html#astropy.io.misc.hdf5 。 write_table_hdf5;您可以在源代码中看到路径变量未用于exists检查)。它不是文件系统路径,因此您的os.path.exists检查似乎在错误的位置。

因此,(1)检查os.getcwd并查看那里是否dat.h5存在,以及(2)尝试dat_cube.write(os.path.join(runpath, 'dat.h5'), format='hdf5', path="mypath")

于 2015-11-02T07:02:49.093 回答