2014年6月26日木曜日

開発環境

Head First Python (Paul Barry(著)、 O'Reilly Media )のChapter 7(Web Development: Putting it all together)、SHARPEN YOUR PENCIL(p.245)を解いてみる。

SHARPEN YOUR PENCIL(p.245)

コード(BBEdit)

/cgi-bin/generate_timing_data.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import cgi
import yate
import athletemodel

from_data = cgi.FieldStorage()
athlete_name = from_data['which_athlete'].value
athletes = athletemodel.get_from_store()
athlete = athletes[athlete_name]

print(yate.start_response())
print(yate.include_header('Timing data for {0}'.format(athlete_name)))
print(yate.header('Date of birth: {0}'.format(athlete.dob)))
print(yate.para('top3'))
print(yate.u_list(athlete.top3()))
print(yate.include_footer(
    {'Home':'/index.html', 'Select another athlete':'generate_list.py'}))

入出力結果(Terminal)

$ ./simple_httpd.py 
Starting simple_httpd on port: 8080
127.0.0.1 - - [26/Jun/2014 14:02:43] "GET /cgi-bin/generate_list.py HTTP/1.1" 200 -
127.0.0.1 - - [26/Jun/2014 14:02:46] "POST /cgi-bin/generate_timing_data.py HTTP/1.1" 200 -
Traceback (most recent call last):
  File "/Users/kamimura/Documents/py/hfpy/chapter7/webapp/cgi-bin/generate_timing_data.py", line 17, in <module>
    print(yate.u_list(athlete.top3()))
TypeError: 'list' object is not callable
127.0.0.1 - - [26/Jun/2014 14:02:46] CGI script exit status 0x100
  C-c C-cTraceback (most recent call last):
  File "./simple_httpd.py", line 10, in <module>
    httpd.serve_forever()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socketserver.py", line 236, in serve_forever
    poll_interval)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socketserver.py", line 154, in _eintr_retry
    return func(*args)
KeyboardInterrupt
$

0 コメント:

コメントを投稿