我有两个python文件。一个是nnet_comb_mod.py,另一个是nnet_flask.py,它创建一种形式来获取运行nnet_comb_mod.py文件的参数。 nnet_comb_mod.py以
运行python3 nnet_comb_mod.py some_file.csv 15 21 1000 5000 0.8 1.2
,其中所有数字和浮点数都作为sys.argv [x]访问。 nnet_flask.py代码是:
import nnet_comb_mod
# import other modules
app = Flask(__name__)
@app.route('/')
def upload_file():
return '''<html><h1>Upload a file</h1>
<body><form action = "http://127.0.0.1:8085/fup" method = "POST" enctype ="multipart/form-data">
<input type="file" name="file"/>
<input type="number" name="low_hl"/>
...
<input type="submit"/></form></body></html> '''
@app.route('/fup',methods=['GET','POST'])
def upload_link():
if request.method == 'POST':
f = request.files['file']
g = request.form.get('low_hl')
...
app.config['upfls'] = "./"
f.save(os.path.join(app.config['upfls'], f.filename))
f.close()
cmd2 = "python nnet_comb_mod.py ./"+f.filename+" "+g+" "+h+" "+i+" "+j+" "+k+" "+l
cmd2 = str(cmd2)
g = proc2.Group()
p2 = g.run(cmd2)
def read():
while g.is_pending():
lines = g.readlines()
for proc,line in lines:
yield str(line) + "\n"
return Response(read() , mimetype = 'text/event-stream')
if __name__ == '__main__':
app.run(host='0.0.0.0',port=8085,debug=True)
它抛出错误:
File "H:\nnet_comb_mod.py", line 35, in <module>
hidlay_btm = sys.argv[2]
IndexError: list index out of range
如何获取烧瓶形式的数据作为nnet_comb_mod.py的参数?