如何在python中为多个输入执行Fortran程序

时间:2017-02-16 06:03:15

标签: python python-2.7 python-3.x bioinformatics biopython

我有一个Fortran程序,想在python中为多个文件执行它。我有2000个输入文件,但在我的Fortran代码中,我一次只能运行一个文件。我应该如何在python中调用Fortran程序?

我的剧本:

import subprocess
import glob
input = glob.glob('C:/Users/Vishnu/Desktop/Fortran_Program_Rum/*.txt')
output = glob.glob('C:/Users/Vishnu/Desktop/Fortran_Program_Rum/Output/')
f = open("output", "w")
for i in input:
    subprocess.Popen(["FORTRAN ~/C:/Users/Vishnu/Desktop/Fortran_Program_Rum/phase1.f", "--domain "+i])
f.write(i)

错误:

Traceback (most recent call last):
  File "<pyshell#14>", line 2, in <module>
subprocess.Popen(["FORTRAN ~/C:/Users/Vishnu/Desktop/Fortran_Program_Rum/phase1.f", "--domain "+i])
  File "C:\Users\Vishnu\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
  File "C:\Users\Vishnu\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

1 个答案:

答案 0 :(得分:0)

也许用subprocess这个线程调用fortran程序?

Calling an external command in Python

e.g。

import subprocess
subprocess.call('fortran program.f', '-flags')

另外,read the documentation