我有一个 python 脚本,它获取三个输入:它应该读取一个 fit 文件(fil1.fits、file2.fits ......)并从 csv 文件(name.csv)中获取变量“A”和“B”;第一列是“A”,第二列是“B”。所有 fit 文件和 scv 文件都在同一个文件夹中。简而言之,我的代码如下:def kinematic(): file = 'Desktop/data/test/spec-001.fits' hdu = fits.open(file) Flux = 'flux' A = 2.31 B = optic # here is what the script does ... # here is what the script does ...if __name__ == '__main__': kinematics()你能指导我如何同时为多个输入运行它吗?
1 回答
浮云间
TA贡献1829条经验 获得超4个赞
尝试以下相同的代码从同一文件夹一次导入多个文件:
import glob
files = glob.glob("*.fits") # get all the file names
for file in files:
with open(file,'r') as f:
lines=read(f) # depending on the file format you can use different function for reading file and then parse it.
添加回答
举报
0/150
提交
取消
