<p>我学习了如何在2.7版的python中编写脚本;但是,我正在编写代码的系统现在只有2.4.3版。我试图打开一个名为输入.csv,读取第0、1、2和3列,同时跳过第一行,因为它包含我不需要的头信息。我附加的代码可以很好地与Python2.7.9一起使用,但不能用于2.4.3。有人能告诉我这段代码应该怎么写吗。在</p>
<pre><code>import csv # imports the library that enables functionality to read .csv files
MATPRO_Temperature = [] # List to hold MATPRO experimental temperatures
MATPRO_Density = [] # List to hold MATPRO experimental densities
MATPRO_Conductivity = [] # List to hold MATPRO experimental thermal conductivities
MATPRO_References = [] # List to hold MATPRO references for each measurement
File_Name = 'Input.csv' # - The relative address for the MATPRO database containing
# the thermal conductivity measurements
# This section opens the .csv file at the address 'File_Name' and reads in its data into lists
with open(File_Name) as csvfile:
next(csvfile) # This forces the reader to skip the header row of hte .csv file
readCSV = csv.reader(csvfile, delimiter = ',')
for row in readCSV:
MATPRO_Temperature.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(row[0])
MATPRO_Density.append(row[1])
MATPRO_Conductivity.append(row[2])
MATPRO_References.append(row[3])
</code></pre>