Python 3.x Python csv比较头

Python 3.x Python csv比较头,python-3.x,Python 3.x,我对python非常陌生,有一个问题。我想读取多个csv文件,检查文件头并比较文件头 from tkinter import Tk from tkinter.filedialog import askopenfilenames import csv root = Tk() files= askopenfilenames(parent=root, title='Choose files') for i in range(len(files)): f = open('{}'.format(f

我对python非常陌生,有一个问题。我想读取多个csv文件,检查文件头并比较文件头

from tkinter import Tk
from tkinter.filedialog import askopenfilenames
import csv
root = Tk()
files= askopenfilenames(parent=root, title='Choose files')

for i in range(len(files)):
   f = open('{}'.format(files[i])) 
   reader = csv.DictReader(f)
   row = next(reader)
这就是我已有的代码。我的问题是,我不知道如何读取文件头并比较它们

我试过了

    row[i] = next(reader)

但这不起作用。

一个简单的Python示例,它读取一组文件并比较它们的头

last_header = None
# Loop through the files
for file in files:
    with open(file) as f:
        # Read the header
        header = f.readline()
        # If this is the first file, then store the
        # header for later comparison
        if last_header == None:
            last_header = header
        # Check that the header match the last header
        elif header != last_header:
            print("Some information to user")
            quit()
        # Read the remaining lines
        lines = f.readlines()

这很难帮助。你能说明你需要比较的方式/内容吗?所有标题都必须相等,还是要存储差异?