Py学习  »  Python

python_数据['division']中的语法无效。追加(int(拆分[3]))

NMOLL • 3 年前 • 1158 次点击  

获取无效语法,但不确定原因。请参阅包含以下代码的行:data['division']。追加(int(拆分[3]))

def getBMData(filename):
    """Read the contents of the given file. Assumes the file
    in a comma-seperated format, with 6 elements in each entry:
    0. Name (string), 1. Gender (string), 2. Age (int),
    3. Division (int), 4. Country (string), 5. Overall time (float)
    Returns: dict containing a list for each of the 6 variables."""
    
    data = {}
    f = open(filename)
    line = f.readline()
    data['name'], data['gender'], data['age'] = [], [], []
    data['division'], data['country'], data['time'] = [], [], []
    while line != '':
        split = line.split(',')
        data['name'].append(split[0])
        data['gender'].append(split[1])
        data['age'].append(int(split[2])
        data['division'].append(int(split[3]))
        data['country'].append(split[4])
        data['time'].append(float(split[5][:-1])) #remove \n
        line = f.readline()
    f.close()
    return data
                           
   
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/132192
 
1158 次点击  
文章 [ 1 ]  |  最新文章 3 年前