# -*- coding:utf-8 -*- import athletemodel the_files=["../chapter6/james2.txt","../chapter6/julie2.txt","../chapter6/mikey2.txt","../chapter6/sarah2.txt"] data=athletemodel.put_to_store(the_files) data_copy=athletemodel.get_from_store() for each_data in data_copy: print(data_copy[each_data].name+" "+data_copy[each_data].dob)
#! /usr/bin/env python import cgitb cgitb.enable() import cgi import yate import athletemodel athletes = athletemodel.get_from_store() form_data = cgi.FieldStorage() if "which_athlete" not in form_data: print "<H1>Error</H1>" print "Please choose one athlete." athlete_name = form_data["which_athlete"].value the_athlete = athletes[athlete_name] print yate.start_response() print yate.include_header("Coach Kelly's Timing Data") print yate.header("Athlete:" + athlete_name + ", DOB:" + the_athlete.dob + ".") print yate.para("The top times for " + athlete_name + " are:") print yate.u_list(the_athlete.top3) print yate.include_footer({"Home":"index.html", "Select another athlete":"generate_list.py"})
import cgi import cgitb #开启浏览器追踪 cig 信息 import athletemodel import YATE cgitb.enable()#cgitb #开启浏览器追踪 cig 信息 athletes = athletemodel.get_from_store()#从pickle获取信息 form_data = cgi.FieldStorage()#获取请求的form的内容 athlete_name = form_data['which_athlete'].value#从内容中得到请求控件name 为:which_athlete的值 print(YATE.start_response()) print(YATE.include_header('Timing Data')) print(YATE.header('Althlete:'+athlete_name+' ,DOB: ' +athletes[athlete_name].dob+'.')) print(YATE.para('The top times for this athlete are:')) print(YATE.u_list(athletes[athlete_name].top3))#这里需要在top3方法那加入@property将类方法表现得像个类属性 print(YATE.include_footer({'Home':'/index.html', 'Select another athlete':'generate_list.py'}))
#! /usr/local/bin/python3 import cgi import cgitb cgitb.enable() import athletemodel import yate athletes = athletemodel.get_from_store() form_data = cgi.FieldStorage() athlete_name = form_data['which_athlete'].value print(yate.start_response()) print(yate.include_header("Coach Kelly's Timing Data")) print( yate.header("Athlete: " + athlete_name + ", DOB: " + athletes[athlete_name].dob + ".")) print(yate.para("The top times for this athlete are:")) print(yate.u_list(athletes[athlete_name].top3())) print( yate.include_footer({ "Home": "/index.html", "Select another athlete": "generate_list.py" }))
# -*- coding:utf-8 -*- import athletemodel the_files = [ "../chapter6/james2.txt", "../chapter6/julie2.txt", "../chapter6/mikey2.txt", "../chapter6/sarah2.txt" ] data = athletemodel.put_to_store(the_files) data_copy = athletemodel.get_from_store() for each_data in data_copy: print(data_copy[each_data].name + " " + data_copy[each_data].dob)
import cgi import cgitb #开启浏览器追踪 cig 信息 import athletemodel import YATE cgitb.enable() #cgitb #开启浏览器追踪 cig 信息 athletes = athletemodel.get_from_store() #从pickle获取信息 form_data = cgi.FieldStorage() #获取请求的form的内容 athlete_name = form_data[ 'which_athlete'].value #从内容中得到请求控件name 为:which_athlete的值 print(YATE.start_response()) print(YATE.include_header('Timing Data')) print( YATE.header('Althlete:' + athlete_name + ' ,DOB: ' + athletes[athlete_name].dob + '.')) print(YATE.para('The top times for this athlete are:')) print(YATE.u_list( athletes[athlete_name].top3)) #这里需要在top3方法那加入@property将类方法表现得像个类属性 print( YATE.include_footer({ 'Home': '/index.html', 'Select another athlete': 'generate_list.py' }))
from athletemodel import put_to_store, get_from_store # 선수들의 데이터가 담긴 파일 목 the_files = ["../data/james.txt", "../data/julie.txt", "../data/mikey.txt", "../data/sarah.txt"] # 선수들의 파일 목록을 읽어서 각 파일의 내용을 AthleteList 객체로 변환 후, 이름을 key로 하여 전체를 하나의 dictionary 객체로 만들고, # 이를 pickle로 저장하는 함수 put_to_store(the_files) # 저장된 pickle에서 dictionary 객체를 불러와 athletes 변수에 저장 athletes = get_from_store() # 확인 용 출력 print(athletes) print(athletes['Julie Jones'].clean_data) print(athletes['Julie Jones'].top3) # 생일 출력하기 for each in athletes: print(athletes[each].name + ' ' + athletes[each].dob)