astropy.table.write() IOError: File exists:

astropy.table.write() IOError: File exists:

我正在使用 astropy.table.write(filename, path=run_dir) 将 astropy table 写入名为 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

path 变量是一个路径 within hdf5 文件(参见 http://docs.astropy.org/en/stable/api/astropy.io.misc.hdf5.write_table_hdf5.html#astropy.io.misc.hdf5.write_table_hdf5; you can see in the source 路径变量不用于 exists 检查)。它不是文件系统路径,因此您的 os.path.exists 检查似乎找错了地方。

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