如何在读取两个输入文件时多次运行python脚本

我有一个 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()

你能指导我如何同时为多个输入运行它吗?


慕哥9229398
浏览 122回答 1
1回答

浮云间

尝试以下相同的代码从同一文件夹一次导入多个文件:import globfiles = glob.glob("*.fits") # get all the file namesfor 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.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python