我有一個 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
提交
取消