我用Python编写了一个小脚本,使用一个名为tempo2的天文学命令行工具,它创建了一个名为“polyco_new.dat”的文件。我想使用filepath重命名新创建的文件
import os, sys
import numpy as np
with open('paths.txt', 'r') as paths_list:
for file_path in paths_list:
data = np.loadtxt(file_path.strip())
filename = file_path[-26:-5]
# creates the 'polyco_new.dat'-file
os.system("tempo2 -tempo1 -polyco \"%f %f 120 15 12 @ 0\" -f ephemerides.par" %(t0, te))
# renames the file
os.rename('polyco_new.dat', 'polycox_'+filename+'.dat')
然而,我得到的错误是“polyco_new.dat”不存在(没有这样的文件或目录),即使我知道它是由tempo2工具创建的
我怎样才能使这个代码工作
问题可能在于
tempo2
默认用于创建文件的目录与启动Python脚本的当前工作目录之间的差异。要解决此问题,请执行以下操作:相关问题 更多 >
编程相关推荐