python - File Parsing on the fly in Flask -


i received advice on question regarding easy use web-framework use simple project helping friend , suggested use flask.

everything has been working out far - trying figure out how (or if possible) read file on fly, , pass contents of file function have.

for instance, want use following:

html side:

<form action="process_file" method=post enctype=multipart/form-data>      <input type='file' name='file'>      <input type='submit' value="upload , process selected file">  </form>  

i figure need on actual page using html, allow me path of file need, able read said-file.

i unsure go on flask/python side of things - i'm looking step in right direction, perhaps reading in 2 numbers or letters (in file) , outputting them on same page?

flask/python side:

@app.route('/process_file', methods=['get', 'post']) def process_file():     if request.method == 'post':         file = request.files.get('file')         if file:             "read file , parse values array?"             "pass arguments processing function , outputs result x)"             return render_template('index.html',answer = x)         else:             return render_template('index.html',error=1) 

i'm not sure if headed in right direction - thought more experience flask / python lead me there.

edit: noticed flask seems play jquery, using them in combination make processing / file-parsing simpler?

thanks everyone.

the documentation on flask site (http://flask.pocoo.org/docs/patterns/fileuploads/) demonstrates how , safely handle file uploads, start there. if wish parse file before/instead of saving it, should able use stream property/attribute on filestorage object you're given access via request.files.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -