小编Vla*_*mir的帖子

Python错误:TypeError:'模块'对象不能为HeadFirst Python代码调用

我正在关注HeadFirst Python书中的教程.在第7章中,我在尝试运行下一个代码时收到错误消息:

运动员班:

class AthleteList(list):
    def __init__(self, a_name, a_dob=None, a_times=[]):
        list.__init__([])
        self.name = a_name
        self.dob = a_dob
        self.extend(a_times)

    def top3(self):
        return(sorted(set([sanitize(t) for t in self]))[0:3])

def get_coach_data(filename):
    try:
        with open(filename) as f:
            data = f.readline()
        templ = data.strip().split(',')
        return(AthleteList(templ.pop(0), templ.pop(0), templ))
    except IOError as ioerr:
        print('File error: ' + str(ioerr))
        return(None)

def sanitize(time_string):
    if '-' in time_string:
        splitter = '-'
    elif ':' in time_string:
        splitter = ':'
    else:
        return(time_string)
    (mins, secs) = time_string.split(splitter)
    return(mins + '.' + secs)
Run Code Online (Sandbox Code Playgroud)

在下一个模块中,我做了一些测试:

import …
Run Code Online (Sandbox Code Playgroud)

python module

16
推荐指数
2
解决办法
8万
查看次数

标签 统计

module ×1

python ×1