为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕哥9229398 2022-06-02 16:45:33
我有一个 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.



查看完整回答
反对 回复 2022-06-02
  • 1 回答
  • 0 关注
  • 121 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号