dimanche 30 septembre 2018

Read the data of the CSV file uploaded from the user

I'm trying to write a Python/Flask script that transforms a csv file into some other file. I've developed a UI so that user can upload a CSV file. I'm having a hard time trying to figure out how to read the data of that CSV file, uploaded from the user.

@app.route('/import', methods=['GET', 'POST'])
    def upload():
        if request.method == 'POST':
            file = request.files['file']
            if not file.filename:
                errors.append("Please select a file!")
            else:
                ...
                data = [GET CSV DATA HERE]
                process_data(data)

How could I get the data from the CSV file so that I could pass on the following method:

def process_data(file):
    with open(file, 'r') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        ...

Thank you in advance!




Aucun commentaire:

Enregistrer un commentaire