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

如何在 python Flask 中对两个或多个 CSV 文件进行验证

如何在 python Flask 中对两个或多个 CSV 文件进行验证

慕哥9229398 2021-09-28 16:11:41
请在不喜欢这个问题之前问我你不明白的地方大家好,我有数据生成程序,它会做很多计算,所以我不能在这里粘贴我的整个程序,所以只谈论我的程序 程序的所有计算都从阅读文件,所以当我在“选择文件”选项的网页中选择多个 CSV 文件时,我需要验证所有 csv 文件的列号(应该相同),列标题名称也应该匹配..我编写的程序是像这样:from flask import Flask, render_templateimport osimport csvimport pandas as pdimport numpy as npapp = Flask(__name__)APP_ROOT = os.path.dirname(os.path.abspath(__file__))@app.route("/")def index():    print("Loading the root file")    return render_template("upload.html")@app.route("/upload", methods=['POST'])def upload():    target = os.path.join(APP_ROOT, 'input/')        print("target-",target)        if not os.path.isdir(target):            os.mkdir(target)    for file in request.files.getlist("source_fileName"):            print("file-",file)            filename = file.filename            print("filename-",filename)            destination = "/".join([target, filename])            print("destination-",destination)            file.save(destination)            print("file>",file)            global tempFile            tempFile = destination            print("tempFile - " + tempFile)    return redirect("/compute", )def compute():    readerForRowCheck = pd.read_csv(tempFile)        for row in readerForRowCheck:            if (len(row) != 8):                return render_template("Incomplete.html")            headerColumn1 = row[0];            headerColumn2 = row[1];            headerColumn3 = row[2];            headerColumn4 = row[3];            headerColumn5 = row[4];            headerColumn6 = row[5];            headerColumn7 = row[6];            headerColumn8 = row[7];
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 207 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信