Python 3.x 与'合作&引用;变量"';Python中的结构

Python 3.x 与'合作&引用;变量"';Python中的结构,python-3.x,list,data-structures,tuples,Python 3.x,List,Data Structures,Tuples,因此,在将CSV文件读入python时,一些变量具有以下结构: “变量” 我将它们存储在列出的元组中。 现在,这些变量中的一些必须相互比较,因为它们是数值型的。 但我似乎找不到一种方法来比较它们。例如: counter = 0 if '"120000"' < '"130000"': counter += 1 我阅读文件如下: with open(dataset, mode="r") as flight_infor

因此,在将CSV文件读入python时,一些变量具有以下结构: “变量” 我将它们存储在列出的元组中。 现在,这些变量中的一些必须相互比较,因为它们是数值型的。 但我似乎找不到一种方法来比较它们。例如:

counter = 0
if '"120000"' < '"130000"':
        counter += 1
我阅读文件如下:

with open(dataset, mode="r") as flight_information:
    flight_information_header = flight_information.readline()
    flight_information = flight_information.read()
    flight_information = flight_information.splitlines()
    flight_information_list = []
    for lines in flight_information:
        lines = lines.split(",")
        flight_information_tuple = tuple(lines)
        flight_information_list.append(flight_information_tuple)

对于未来的人来说,以下几点解决了我的问题: 由于元组是不可变的,我现在在加载csv文件时删除了数值周围的“”

例如:

with open(dataset, mode="r") as flight_information:
    flight_information_header = flight_information.readline()
    flight_information = flight_information.read()
    flight_information = flight_information.splitlines()
    flight_information_list = []
    for lines in flight_information:
        lines = lines.replace('"', '').split(",")
        flight_information_tuple = tuple(lines)
        flight_information_list.append(flight_information_tuple)
请特别注意这一行:

lines = lines.replace('"', '').split(",")

你能提供更多的上下文吗?你是如何从CSV中读取的,它看起来像什么,这些数值是如何被引用的?你可以在转换为整数之前去掉引号,但最好在上游修复。将我的代码作为答案发布它不是答案,请将其编辑到问题中。为什么整数以引号开头?在CSV文件的构建过程中,无法对其进行任何更改。那么您是否尝试将引号去掉?有很多方法可以做到这一点,请参见。
lines = lines.replace('"', '').split(",")